#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, Q;
  long long A[100010];
  long long B[100010];
  long long C[100010];
  cin >> N;
  for (long long i = 0; i < N; i++) {
    long long tmp;
    cin >> tmp;
    A[tmp]++;
  }
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    cin >> B[i];
    cin >> C[i];
  }
  long long res = 0;
  for (long long j = 1; j < 100010; j++) {
    if (A[j] > 0) {
      res += A[j] * j;
    }
  }
  for (long long i = 0; i < Q; i++) {
    res -= B[i] * A[B[i]];
    res -= C[i] * A[C[i]];
    A[C[i]] += A[B[i]];
    B[i] = 0;
    res += B[i] * A[B[i]];
    res += C[i] * A[C[i]];
    cout << res << endl;
  }
  return 0;
}
