#include <bits/stdc++.h>
int main() {
  int n, i, q, j, b, c, input, out = 0;
  scanf("%d", &n);
  int a[200000] = {0};
  for (i = 0; i < n; i++) {
    scanf("%d", &input);
    a[input]++;
    out = out + input;
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d %d", &b, &c);
    if (a[b] == 0)
      out = out;
    else {
      out = out + (c - b) * a[b];
      a[c] = a[c] + a[b];
      a[b] = 0;
    }
    printf("%d\n", out);
  }
  return 0;
}
