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