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