#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001000;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
int main() {
  long long N;
  cin >> N;
  map<long long, long long> cnt;
  long long ans = 0;
  for (int i = 0; i < N; ++i) {
    long long t;
    cin >> t;
    cnt[t]++;
    ans += t;
  }
  long long Q;
  cin >> Q;
  vector<pair<int, int> > query(Q);
  for (int i = 0; i < Q; ++i) cin >> query[i].first >> query[i].second;
  for (int i = 0; i < Q; ++i) {
    long long kazu = cnt[query[i].first];
    cnt[query[i].second] += kazu;
    ans += (query[i].second - query[i].first) * kazu;
    cout << ans << endl;
  }
  return 0;
}
