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