#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> D(100000);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    D.at(A.at(i))++;
  }
  long S = 0;
  for (int i = 0; i < N; i++) {
    S = S + 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) >> C.at(i);
    S = S + (C.at(i) - B.at(i)) * D.at(B.at(i));
    D.at(C.at(i)) = D.at(C.at(i)) + D.at(B.at(i));
    D.at(B.at(i)) = 0;
    cout << S << endl;
  }
}
