#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<int> A;
  A.resize(N);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  int Q;
  cin >> Q;
  vector<int> B, C;
  B.resize(Q);
  C.resize(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  vector<int> cnt;
  cnt.resize(100010);
  fill(cnt.begin(), cnt.end(), 0);
  for (int n : A) {
    cnt[n]++;
  }
  for (int i = 0; i < Q; i++) {
    sum = sum + C[i] * cnt[B[i]] - B[i] * cnt[B[i]];
    cnt[C[i]] += cnt[B[i]];
    cnt[B[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
