#include <bits/stdc++.h>
int main() {
  int a[100000], b[100000], c[100000], n, q, i, j, ans;
  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++) {
    for (j = 0; j < n; j++) {
      if (a[j] == b[i]) a[j] = c[i];
    }
    ans = 0;
    for (j = 0; j < n; j++) ans += a[j];
    printf("%d\n", ans);
  }
}
