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