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