#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> b(n);
  map<int, int> ma;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int s;
    cin >> s;
    b[i] = s;
    ma[s]++;
    ans += s;
  }
  cin >> q;
  int B, C;
  for (int i = 0; i < q; i++) {
    cin >> B >> C;
    decltype(ma)::iterator it = ma.find(B);
    if (it != ma.end()) {
      int tem = C - B;
      ans = ans + ma[B] * tem;
      ma[C] += ma[B];
      ma[B] = 0;
    }
    cout << ans << endl;
  }
  return 0;
}
