#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  long long A_sum = 0;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    A_sum += 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);
  }
  map<int, int> n;
  for (int i = 0; i < N; i++) {
    n[A.at(i)]++;
  }
  for (int i = 0; i < Q; i++) {
    if (n.find(B.at(i)) == n.end()) {
      cout << A_sum << endl;
      continue;
    }
    A_sum = A_sum - n.at(B.at(i)) * B.at(i) + n.at(B.at(i)) * C.at(i);
    n[C.at(i)] += n.at(B.at(i));
    n[B.at(i)] = 0;
    cout << A_sum << endl;
  }
  return 0;
}
