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