#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long v = 0;
  vector<int> a(n);
  vector<int> ac(100001, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ac[a[i]] += 1;
    v += a[i];
  }
  int q;
  cin >> q;
  for (int j = 0; j < q; j++) {
    int b, c;
    cin >> b >> c;
    if (ac[b] > 0) {
      v -= (long long)(ac[b] * b);
      v += (long long)(ac[b] * c);
      ac[c] += ac[b];
      ac[b] = 0;
    }
    cout << v << endl;
  }
  return 0;
}
