#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  int total = 0;
  unordered_map<int, int> d;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    total += a;
    if (d.count(a)) {
      d[a]++;
    } else {
      d[a] = 1;
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (d.count(b)) {
      total += (c - b) * d[b];
      d[c] += d[b];
      d.erase(b);
    }
    cout << total << "\n";
  }
  return 0;
}
