#include <bits/stdc++.h>
int main(void) {
  int b, c, d, n, q, i, j;
  long int sum = 0;
  scanf("%d", &n);
  int a[20000] = {0};
  for (i = 0; i < n; i++) {
    scanf("%d", &d);
    a[d]++;
    sum += d;
  }
  scanf("%d", &q);
  long int s[q];
  for (i = 0; i < q; i++) s[i] = 0;
  for (i = 0; i < q; i++) {
    scanf("%d%d", &b, &c);
    if (a[b] >= 1) {
      sum = sum + (c - b) * a[b];
      a[c] = a[c] + a[b];
      a[b] = 0;
    }
    printf("%ld\n", sum);
  }
  return 0;
}
