#include <bits/stdc++.h>
int main(void) {
  int num[10010] = {0};
  long long int sum = 0;
  int seq, treat, tmp1, tmp2;
  scanf("%d", &seq);
  for (int i = 1; i <= seq; i++) {
    scanf("%d", &tmp1);
    sum += tmp1;
    num[tmp1]++;
  }
  scanf("%d", &treat);
  for (int i = 0; i < treat; i++) {
    scanf("%d%d", &tmp1, &tmp2);
    sum += (tmp2 - tmp1) * num[tmp1];
    num[tmp2] += num[tmp1];
    num[tmp1] -= num[tmp1];
    printf("%lld\n", sum);
  }
  return 0;
}
