#include <bits/stdc++.h>
void sumA(int *a, int n) {
  long int sum;
  sum = 0;
  for (int i = 0; i < n; i++) {
    sum += *(a + i);
  }
  printf("%ld\n", sum);
}
int main(void) {
  int N;
  scanf("%d", &N);
  int *a;
  a = (int *)malloc(N * sizeof(int));
  for (int i = 0; i < N; i++) {
    scanf("%d", &(*(a + i)));
  }
  int Q;
  scanf("%d", &Q);
  int B, C;
  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;
    }
    sumA(a, N);
  }
  free(a);
  return 0;
}
