#include <bits/stdc++.h>
int main(void) {
  int N, A[100000] = {0}, str, i;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &str);
    A[str - 1] += 1;
  }
  int Q, b, c, j, sum;
  scanf("%d", &Q);
  for (i = 0; i < Q; i++) {
    scanf("%d %d", &b, &c);
    A[c - 1] += A[b - 1];
    A[b - 1] = 0;
    sum = 0;
    for (j = 0; j < 100000; j++) {
      sum += A[j] * (j + 1);
    }
    printf("%d\n", sum);
  }
  return 0;
}
