#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int sum = 0;
  map<int, int> d;
  for (int i = 0; i < N; i++) {
    int a_i;
    cin >> a_i;
    sum += a_i;
    decltype(d)::iterator iter = d.find(a_i);
    if (iter != d.end()) {
      int tmp = d.at(a_i);
      d.erase(a_i);
      d.insert(make_pair(a_i, tmp + 1));
    } else {
      d.insert(make_pair(a_i, 1));
    }
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B_i, C_i;
    cin >> B_i >> C_i;
    decltype(d)::iterator iter = d.find(B_i);
    if (iter == d.end()) {
      cout << sum << endl;
    } else {
      sum += ((C_i - B_i) * d.at(B_i));
      int tmp = d.at(B_i);
      d.erase(B_i);
      decltype(d)::iterator iter2 = d.find(C_i);
      if (iter2 == d.end()) {
        d.insert(make_pair(C_i, tmp));
      } else {
        int tmp2 = d.at(C_i);
        d.erase(C_i);
        d.insert(make_pair(C_i, tmp + tmp2));
      }
      cout << sum << endl;
    }
  }
  return 0;
}
