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