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