#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, flag = 0, ans = 0;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  cin >> t;
  while (t--) {
    int sum = 0;
    sort(v.begin(), v.end());
    vector<int>::iterator upper, lower;
    int x, y;
    cin >> x >> y;
    upper = upper_bound(v.begin(), v.end(), x);
    lower = lower_bound(v.begin(), v.end(), x);
    int f = upper - v.begin();
    int g = lower - v.begin();
    for (int i = g; i < f; i++) v[i] = y;
    for (int i = 0; i < n; i++) sum += v[i];
    cout << sum << endl;
  }
  return 0;
}
