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