#include <bits/stdc++.h>
int main(void) {
  int n, q;
  int i, j = 0;
  int *a = (int *)malloc(400000);
  int *b = (int *)malloc(400000);
  int *c = (int *)malloc(400000);
  long int total = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", (a + i));
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d %d", (b + i), (c + i));
  }
  while (1) {
    for (i = 0; i < n; i++) {
      if (*(a + i) == *(b + j)) {
        *(a + i) = *(c + j);
      }
      total += *(a + i);
    }
    printf("%ld\n", total);
    total = 0;
    j++;
    if (j == q) {
      break;
    }
  }
  return 0;
}
