#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long mod = 998244353;
int inf = 1000001000;
long long INF = 1e18 + 5;
int main() {
  long long N, Q;
  cin >> N;
  long long suma = 0;
  vector<long long> a(N);
  map<long long, long long> mp;
  for (long long i = (0); i < (long long)(N); i++) {
    cin >> a[i];
    suma += a[i];
    mp[a[i]]++;
  }
  cin >> Q;
  vector<long long> b(Q), c(Q);
  for (long long i = (0); i < (long long)(Q); i++) {
    cin >> b[i] >> c[i];
    if (mp[b[i]] == 0) {
      cout << suma << endl;
      continue;
    } else {
      suma += (c[i] - b[i]) * mp[b[i]];
      if (mp[c[i]] > 0)
        mp[c[i]]++;
      else
        mp[c[i]] = mp[b[i]];
      mp[b[i]] = 0;
    }
    cout << suma << endl;
  }
  return 0;
}
