#include <bits/stdc++.h>
int main() {
  int N, Q, sum, B, C, i, j;
  scanf("%d", &N);
  int A[N + 1];
  for (i = 0; i < N; i++) scanf("%d", &A[i]);
  scanf("%d", &Q);
  for (i = 0; i < Q; i++) {
    scanf("%d %d", &B, &C);
    sum = 0;
    for (j = 0; j < N; j++) {
      if (A[j] == B) A[j] = C;
      sum = sum + A[j];
    }
    printf("%d\n", sum);
  }
  return 0;
}
