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