#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, j, ar[100000], q, i, b, c, sum;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> ar[i];
  }
  cin >> q;
  while (q--) {
    sum = 0;
    cin >> b >> c;
    for (j = 0; j < n; j++) {
      if (ar[j] == q) {
        ar[j] = c;
      }
      sum = sum + ar[j];
    }
    cout << sum << endl;
  }
}
