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