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