#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  multimap<int, int> Am;
  long sum = 0;
  for (long i = 0; i < N; i++) {
    cin >> A.at(i);
    sum += A.at(i);
    if (Am.count(A.at(i)) == 0) {
      Am.insert(make_pair(A.at(i), 1));
    } else {
      auto poyo = Am.find(A.at(i));
      poyo->second = poyo->second + 1;
    }
  }
  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);
  }
  for (int i = 0; i < Q; i++) {
    if (Am.find(B.at(i)) != Am.end()) {
      auto po = Am.find(B.at(i));
      sum = sum - (po->second) * B.at(i) + (po->second) * C.at(i);
      if (Am.count(C.at(i)) == 0) {
        Am.insert(make_pair(C.at(i), (po->second)));
      } else {
        auto poyo = Am.find(C.at(i));
        poyo->second = poyo->second + (po->second);
      }
      Am.erase(B.at(i));
    }
    cout << sum << endl;
  }
}
