#include <bits/stdc++.h>
int main() {
  int N, Q, a[1 << 6], b[1 << 6], c[1 << 6];
  long int S = 0;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d%d", &b[i], &c[i]);
  }
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < N; j++) {
      if (a[j] == b[i]) {
        a[j] = c[i];
      }
    }
    for (int j = 0; j < N; j++) {
      S = S + (long int)a[j];
    }
    printf("%ld\n", S);
    S = 0;
  }
  return 0;
}
