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