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