#include <bits/stdc++.h>
int main(void) {
  int n = 0;
  int ai[100000] = {0};
  int a = 0;
  int q = 0;
  int b = 0, c = 0;
  long long sum = 0;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &a);
    ai[a]++;
    sum += (long long)a;
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &b, &c);
    sum += (c - b) * ai[b];
    ai[c] += ai[b];
    ai[b] = 0;
    printf("%d\n", sum);
  }
  return 0;
}
