#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char *argv[]) {
  int N;
  cin >> N;
  int *A = new int[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int Q;
  cin >> Q;
  auto *B = new int[Q];
  auto *C = new int[Q];
  for (int qi = 0; qi < Q; ++qi) {
    cin >> B[qi] >> C[qi];
  }
  const int ND = 100000;
  int D[ND] = {0};
  long int S = 0;
  for (int ni = 0; ni < N; ++ni) {
    D[A[ni]]++;
    S += A[ni];
  }
  for (int qi = 0; qi < Q; ++qi) {
    S += D[B[qi]] * (C[qi] - B[qi]);
    D[C[qi]] += D[B[qi]];
    D[B[qi]] = 0;
    cout << S << endl;
  }
  return 0;
}
