#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  long f = 0;
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    f += a.at(i);
  }
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < q; i++) {
    cin >> b.at(i) >> c.at(i);
    sort(a.begin(), a.end());
    int w = n - 1, r = n - 1, q = 0, s = n - 1;
    while (w > 0) {
      if (a.at(q + (w + 1) / 2) < b.at(i)) q += (w + 1) / 2;
      w /= 2;
    }
    while (r > 0) {
      if (a.at(s - (r + 1) / 2) > b.at(i)) s -= (r + 1) / 2;
      r /= 2;
    }
    int j = q;
    if (j == 0)
      if (a.at(j) == b.at(i)) {
        f += c.at(i) - a.at(j);
        a.at(j) = c.at(i);
      }
    q++;
    f += (c.at(i) - a.at(j)) * (s - j);
    for (; j < s; j++) a.at(j) = c.at(i);
    if (s == n - 1)
      if (a.at(s) == b.at(i)) {
        f += c.at(i) - a.at(s);
        a.at(s) == c.at(i);
      }
    cout << f << endl;
  }
}
