#include <bits/stdc++.h>
using namespace std;
long long a[104];
int32_t main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (auto &it : a) cin >> it;
  long long q;
  cin >> q;
  while (q--) {
    long long ans = 0;
    sort(a.begin(), a.end());
    long long k, b;
    cin >> k >> b;
    auto it1 = lower_bound(a.begin(), a.end(), k);
    auto it2 = upper_bound(a.begin(), a.end(), k);
    long long pos1 = it1 - a.begin();
    long long pos = it2 - a.begin();
    for (long long i = pos1; i < pos; i++) a[i] = b;
    for (long long i = 0; i < n; i++) ans += a[i];
    cout << ans << '\n';
  }
  return 0;
}
