#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q, A, B, C;
  unsigned long long S;
  cin >> N;
  map<int, int> M;
  map<int, int>::iterator it, it2;
  for (int i = 0; i < N; i++) {
    cin >> A;
    it = M.find(A);
    if (it == M.end()) {
      M.insert(pair<int, int>(A, 1));
    } else
      it->second += 1;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    it = M.find(B);
    if (it != M.end()) {
      it2 = M.find(C);
      if (it2 == M.end()) {
        M.insert(pair<int, int>(C, it->second));
      } else {
        it2->second += it->second;
      }
      M.erase(it);
    }
    S = 0;
    for (auto it = M.begin(); it != M.end(); it++) {
      S += it->first * it->second;
    }
    cout << S << endl;
  }
  return 0;
}
