#include <bits/stdc++.h>
using namespace std;
const int mod = 1E9 + 7;
const int inf = 1 << 29;
int main() {
  int n;
  cin >> n;
  map<int, int> a;
  int tmp_a;
  int s = 0;
  for (int i = 0; i < (int)(n); i++) {
    cin >> tmp_a;
    a[tmp_a] += 1;
    s += tmp_a;
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < (int)(q); i++) cin >> b[i] >> c[i];
  int cnt_b, cnt_c;
  int prev_s = s;
  for (int i = 0; i < (int)(q); i++) {
    cnt_b = a[b[i]];
    cnt_c = a[c[i]];
    s = prev_s - cnt_b * b[i];
    s += c[i] * cnt_b;
    a.erase(b[i]);
    a.erase(c[i]);
    a.insert({c[i], cnt_b + cnt_c});
    cout << s << endl;
    prev_s = s;
  }
  return 0;
}
