#include <bits/stdc++.h>
int main() {
  using namespace std;
  unsigned long N;
  cin >> N;
  unsigned long S{0};
  vector<unsigned long> cnt(100001);
  for (unsigned long i{0}, A; i < N; ++i) {
    cin >> A;
    S += A;
    ++cnt[A];
  }
  unsigned long Q;
  cin >> Q;
  for (unsigned long i{0}, B, C; i < Q; ++i) {
    cin >> B >> C;
    S -= B * cnt[B];
    S += C * cnt[B];
    cnt[C] += cnt[B];
    cout << S << endl;
  }
  return 0;
}
