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