#include <bits/stdc++.h>
int main(void) {
  int n;
  scanf("%d", &n);
  long long a[100001] = {0}, t, max = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &t);
    a[t]++;
    if (t > max) {
      max = t;
    }
  }
  int q;
  scanf("%d", &q);
  int b[q], c[q];
  long long ans = 0;
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &b[i], &c[i]);
    if (max < c[i]) {
      max = c[i];
    }
    a[c[i]] += a[b[i]];
    a[b[i]] = 0;
    for (int i = 0; i <= max; i++) {
      ans += a[i] * i;
    }
    printf("%lld\n", ans);
    ans = 0;
  }
  return 0;
}
