#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
int main() {
  long long N;
  cin >> N;
  vector<long long> a(N);
  for (long long i = 0; i < N; i++) cin >> a[i];
  long long Q;
  cin >> Q;
  vector<long long> b(N);
  vector<long long> c(N);
  for (long long i = 0; i < Q; i++) cin >> b[i] >> c[i];
  long long ans = 0;
  for (long long i = 0; i < N; i++) ans += a[i];
  map<long long, long long> m;
  for (long long i = 0; i < N; i++) m[a[i]]++;
  for (long long i = 0; i < Q; i++) {
    if (m[b[i]] > 0) {
      ans += (c[i] - b[i]) * m[b[i]];
      m[c[i]] += m[b[i]];
      m[b[i]] = 0;
    }
    cout << ans << endl;
  }
}
