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