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