#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long N, Q, B, C, ans = 0, tmp_A;
  map<long long, long long> A;
  cin >> N;
  for (long long i = 0; i < N; i++) {
    cin >> tmp_A;
    A[tmp_A]++;
  }
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    cin >> B >> C;
    A[C] = A[C] + A[B];
    A[B] = 0;
    ans = 0;
    for (auto j : A) {
      ans = ans + j.first * j.second;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
