#include <bits/stdc++.h>
int main(void) {
  long long int n, q, a[100000], b[100000], c[10000], i, j, k,
      sum[100000] = {0}, wa = 0;
  scanf("%lld", &n);
  for (i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    sum[a[i]]++;
    wa += a[i];
  }
  scanf("%lld", &q);
  for (i = 0; i < q; i++) {
    scanf("%lld%lld", &b[i], &c[i]);
    if (b[i] > c[i]) {
      wa = wa - (b[i] - c[i]) * sum[b[i]];
      sum[c[i]] += sum[b[i]];
      sum[b[i]] = 0;
    } else {
      wa = wa + (c[i] - b[i]) * sum[b[i]];
      sum[c[i]] += sum[b[i]];
      sum[b[i]] = 0;
    }
    printf("%lld\n", wa);
  }
  return 0;
}
