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