#include <bits/stdc++.h>
using namespace std;
void solve(int N, vector<int> A, int Q, vector<int> B, vector<int> C) {
  vector<int> cnt((int)1e5 + 1);
  int64_t res = 0;
  for (int i = 0; i < N; i++) {
    cnt.at(A.at(i))++;
    res += A.at(i);
  }
  for (int iq = 0; iq < Q; iq++) {
    res -= B.at(iq) * cnt.at(B.at(iq));
    res += C.at(iq) * cnt.at(B.at(iq));
    cnt.at(C.at(iq)) += cnt.at(B.at(iq));
    cnt.at(B.at(iq)) = 0;
    cout << res << endl;
  }
}
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int Q;
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B.at(i);
    cin >> C.at(i);
  }
  solve(N, move(A), Q, move(B), move(C));
  return 0;
}
