#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100000;
int main(void) {
  ios::sync_with_stdio(false);
  long long n, a, b, c, s, i, q;
  long long Hash[MAXN] = {0};
  cin >> n;
  for (s = i = 0; i < n; i++) {
    cin >> a;
    Hash[a]++;
    s += a;
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    s += Hash[b] * (c - b);
    Hash[c] += Hash[b];
    Hash[b] = 0;
    cout << s << '\n';
  }
  return 0;
}
