#include <bits/stdc++.h>
int main(void) {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int q;
  scanf("%d", &q);
  int b[q], c[q];
  for (int i = 0; i < q; i++) scanf("%d%d", &b[i], &c[i]);
  for (int i = 0; i < q; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == b[i]) a[j] = c[i];
      sum += a[j];
    }
    printf("%d\n", sum);
  }
}
