#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  cin >> q;
  long int s;
  int b, c;
  for (int i = 0; i < (q); ++i) {
    cin >> b >> c;
    sort(a.begin(), a.end());
    auto it = lower_bound(a.begin(), a.end(), b);
    int index_b = std::distance(a.begin(), it);
    it = lower_bound(a.begin(), a.end(), b + 1);
    int index_a = std::distance(a.begin(), it);
    for (int i = index_b; i < index_a; i++) a[i] = c;
    s = accumulate(a.begin(), a.end(), 0);
    cout << s << endl;
  }
}
