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