#include <bits/stdc++.h>
int main(void) {
  int N, Q;
  int A[100001] = {0};
  int B;
  int C;
  long long sum = 0;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    int tmp;
    scanf("%d", &tmp);
    A[tmp]++;
    sum += tmp;
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d %d", &B, &C);
    sum = sum - (B * A[B]) + (C * A[B]);
    A[C] += A[B];
    A[B] = 0;
    printf("%lld\n", sum);
  }
  return 0;
}
