#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q, a[2][10010];
  cin >> n;
  vector<long long> v(n);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v.at(i);
    sum += v.at(i);
  }
  sort(v.begin(), v.end());
  cin >> q;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> a[i][j];
    }
    for (int k = 0; k < n; k++) {
      if (v.at(k) > a[i][0])
        break;
      else if (v.at(k) < a[i][0])
        continue;
      sum = sum - v.at(k) + a[i][1];
    }
    cout << sum << endl;
  }
}
