#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, Q, A, B, C, n;
  long long ans_tmp = 0;
  long long gap = 0;
  map<long long, long long> cont;
  std::cin >> N;
  for (int i = 0; i < N; i++) {
    std::cin >> A;
    if (cont.count(A)) {
      cont[A] = cont[A] + 1;
    } else {
      cont[A] = 1;
    }
    ans_tmp = ans_tmp + A;
  }
  std::cin >> Q;
  vector<int> ans(Q);
  for (int i = 0; i < Q; i++) {
    std::cin >> B >> C;
    if (cont.count(B)) {
      n = cont[B];
      cont[B] = 0;
      if (cont.count(C)) {
        cont[C] = cont[C] + n;
      } else {
        cont[C] = n;
      }
      ans_tmp = ans_tmp + n * (C - B);
      ans[i] = ans_tmp;
    } else {
      ans[i] = ans_tmp;
    }
  }
  for (int i = 0; i < Q; i++) {
    std::cout << ans[i] << "\n";
  }
}
