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