#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  vector<int> A, B, C;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  cin >> q;
  for (int j = 0; j < q; j++) {
    int b, c;
    cin >> b >> c;
    B.push_back(b);
    C.push_back(c);
  }
  for (int k = 0; k < q; k++) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
      if (A[i] == B[k]) A[i] = C[k];
      sum += A[i];
    }
    cout << sum << endl;
  }
  return 0;
}
