#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s = 0, a;
  cin >> n;
  int h[100000] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a;
    h[a]++;
    s += a;
  }
  int k, i, j;
  cin >> k;
  while (k--) {
    cin >> i >> j;
    if (h[i] != 0) {
      s += (h[i] * j - h[i] * i);
      h[j] += h[i];
      h[i] = 0;
    }
    cout << s << endl;
  }
  return 0;
}
