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