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