#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  map<int, int> A;
  for (int i = 0; i < N; i++) {
    int e;
    cin >> e;
    A[e]++;
  }
  int Q;
  cin >> Q;
  vector<int> B, C;
  B.resize(Q);
  C.resize(Q);
  for (int i = 0; i < Q; i++) cin >> B[i] >> C[i];
  for (int i = 0; i < Q; i++) {
    A[C[i]] += A[B[i]];
    A[B[i]] = 0;
    long long tmp = 0;
    for (int j = 0; j < A.size(); j++) tmp += (long long)j * (long long)A[j];
    cout << tmp << endl;
  }
  return 0;
}
