#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  long long s = 0;
  vector<int> flag(1000001);
  for (int i = 0; i < N; i++) {
    s += A[i];
    flag[A[i]] += 1;
  }
  for (int i = 0; i < Q; i++) {
    if (flag[B[i]] > 0) {
      cout << s - flag[B[i]] * B[i] + flag[B[i]] * C[i] << endl;
      s = s - B[i] + C[i];
      flag[B[i]] = 0;
      flag[C[i]] += B[i];
    } else
      cout << s << endl;
  }
}
