#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  map<long long, long long> mp;
  long long ara[n + 1];
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> ara[i];
    sum += ara[i];
    mp[ara[i]]++;
  }
  long long q;
  cin >> q;
  long long sz = mp.size();
  while (q--) {
    long long b, c, nsz = 0, i;
    cin >> b >> c;
    sum -= mp[b] * b;
    sum += (c * mp[b]);
    mp[c] += mp[b];
    cout << sum << endl;
  }
  return 0;
}
