#include <bits/stdc++.h>
using namespace std;
int main(void) {
  map<int, int> data;
  long n;
  cin >> n;
  for (long i = 0; i < n; i++) {
    long p;
    cin >> p;
    data[p]++;
  }
  long q;
  cin >> q;
  for (long i = 0; i < q; i++) {
    long x, y;
    cin >> x >> y;
    data[y] += data[x];
    data[x] = 0;
    long long ans = 0;
    for (auto it = data.begin(); it != data.end(); it++) {
      ans += (it->first) * (it->second);
    }
    cout << ans << endl;
  }
}
