#include <bits/stdc++.h>
int buc[100001], n, q;
int main() {
  scanf("%d", &n);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    sum += x;
    ++buc[x];
  }
  scanf("%d", &q);
  while (q--) {
    int b, c;
    scanf("%d%d", &b, &c);
    sum -= buc[b] * b;
    sum += buc[b] * c;
    buc[c] += buc[b];
    buc[b] = 0;
    printf("%lld\n", sum);
  }
  return 0;
}
