#include <bits/stdc++.h>
int read_int() {
  int i;
  scanf("%d", &i);
  return i;
}
int conv[100010];
int main() {
  int n = read_int();
  int sum = 0;
  int *a = (int *)malloc(sizeof(int) * n);
  for (int i = 0; i < n; i++) {
    int a = read_int();
    conv[a]++;
    sum += a;
  }
  int q = read_int();
  for (int i = 0; i < q; i++) {
    int b = read_int();
    int c = read_int();
    if (conv[b] == 0) {
      printf("%d\n", sum);
      continue;
    }
    int x = conv[b];
    sum = sum - b * x + c * x;
    printf("%d\n", sum);
    conv[c] += conv[b];
    conv[b] = 0;
  }
  return 0;
}
