#include <bits/stdc++.h>
using namespace std;
int _;
int n, q, a[100050], b[100050], c[100050], cnt[100050], sum = 0;
int main() {
  for (int i = 0; i < 100050; i++) cnt[i] = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    sum += a[i];
    cnt[a[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]) * cnt[b[i]];
    cnt[c[i]] += cnt[b[i]];
    cnt[b[i]] = 0;
    printf("%d\n", sum);
  }
  return 0;
}
