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