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