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