#include <bits/stdc++.h>
using ll = long long;
using namespace std;
constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);
int main(void) {
  int n;
  cin >> n;
  vector<ll> a(n);
  map<ll, int> mp;
  ll sum = 0LL;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    mp[a[i]]++;
    sum += a[i];
  }
  int Q;
  cin >> Q;
  vector<ll> b(n), c(n);
  for (int i = 0; i < Q; ++i) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < Q; ++i) {
    if (mp[b[i]] > 0) {
      sum += (c[i] - b[i]) * mp[b[i]];
      ll tmp = mp[b[i]];
      mp[b[i]] = 0;
      mp[c[i]] += tmp;
    }
    cout << sum << endl;
  }
  return 0;
}
