#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  map<long long, long long> mp;
  for (int i = 0; i < (int)1000000; i++) mp[i] = 0;
  long long ans = 0;
  for (int i = 0; i < (int)n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    ans += a[i];
  }
  long long q;
  cin >> q;
  vector<long long> b(q), c(q);
  for (int i = 0; i < (int)q; i++) cin >> b[i] >> c[i];
  for (int i = 0; i < (int)q; i++) {
    long long r = mp[b[i]];
    ans -= b[i] * mp[b[i]];
    ans += r * c[i];
    mp[c[i]] += mp[b[i]];
    cout << ans << endl;
  }
}
