#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> f;
  int x;
  long long total = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> x;
    f[x]++;
    total += x;
  }
  int q;
  cin >> q;
  int B, C;
  for (int i = 1; i < q + 1; i++) {
    cin >> B >> C;
    int oldnum = B;
    if (f.find(B) != f.end()) {
      total -= (oldnum * f[oldnum]);
      int newno = C;
      f[newno] += f[oldnum];
      total += (f[oldnum] * newno);
      f[oldnum] = 0;
    }
    cout << total << endl;
  }
}
