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