#include <bits/stdc++.h>
int main() {
  int n, sum;
  scanf("%d", &n);
  int A[n];
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  int q;
  scanf("%d", &q);
  int tab[q][2], w[q];
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &tab[i][0], &tab[i][1]);
    for (int j = 0; j < n; j++)
      if (tab[i][0] == A[j]) {
        A[j] = tab[i][1];
        sum = 0;
        for (int k = 0; k < n; k++) sum += A[k];
      }
    w[i] = sum;
  }
  int h = 0;
  while (h < q) {
    printf("\n%d", w[h]);
    h++;
  }
  return 0;
}
