#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q;
  cin >> n;
  long long a[n], i, sum = 0, j = 0;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cin >> q;
  long long b[q], c[q];
  for (i = 1; i <= q; i++) cin >> b[i] >> c[i];
  for (i = 1, j = 1; j <= q; i++) {
    if (a[i] == b[j]) {
      a[i] = c[j];
      sum += a[i];
    } else {
      sum += a[i];
    }
    if (i % n == 0) {
      j++;
      cout << sum << endl;
      sum = 0;
      i = 0;
    }
  }
  return 0;
}
