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