#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  int input;
  for (int i = 0; i < n; i++) {
    cin >> input;
    v.push_back(input);
  }
  sort(v.begin(), v.end());
  int q;
  int b, c;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    auto it = lower_bound(v.begin(), v.end(), b);
    auto it2 = upper_bound(v.begin(), v.end(), b);
    while (it != it2 && it != v.end()) {
      *it = c;
      it++;
    }
    int sum = accumulate(v.begin(), v.end(), 0);
    cout << sum << endl;
    sort(v.begin(), v.end());
  }
}
