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