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