#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, Q, sum = 0, a, A[100000], B[100000], C[100000];
  cin >> N;
  memset(A, 0, sizeof(100000));
  for (long long i = 0; i < N; i++) {
    cin >> a;
    A[a]++;
    sum += a;
  }
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (long long i = 0; i < Q; i++) {
    if (A[B[i]] > 0 && C[i] != B[i]) {
      sum += (C[i] - B[i]) * A[B[i]];
      A[C[i]] += A[B[i]];
      A[B[i]] = 0;
    }
    cout << sum << endl;
  }
  return 0;
}
