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