#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int ton[N], n, q, sum;
signed main() {
  cin >> n;
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    ++ton[x];
    sum += x;
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= ton[b] * b;
    sum += ton[b] * c;
    ton[c] += ton[b];
    ton[b] = 0;
    cout << sum << endl;
  }
  return 0;
}
