#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n), cnt(10001, 0);
  long long s = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
    s += a[i];
  }
  long long q;
  cin >> q;
  vector<long long> b(q), c(q);
  for (long long i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
    s -= (cnt[b[i]] * b[i]);
    s += (cnt[b[i]] * c[i]);
    cnt[c[i]] += cnt[b[i]];
    cnt[b[i]] = 0;
    cout << s << '\n';
  }
  return 0;
}
