#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i <= (long long)(n - 1); i++) cin >> a[i];
  long long q;
  cin >> q;
  sort(a, a + n);
  long long sum = 0;
  for (int i = 0; i <= (long long)(n - 1); i++) sum += a[i];
  for (int i = 1; i <= (long long)(q); i++) {
    long long b, c;
    cin >> b >> c;
    auto itr_bottom = lower_bound(a, a + n, b) - a;
    auto itr_up = lower_bound(a, a + n, b + 0.5) - a;
    sum += (itr_up - itr_bottom) * (c - b);
    for (auto j = itr_bottom; j < itr_up; j++) {
      a[j] = c;
    }
    sort(a, a + n);
    cout << sum << endl;
  }
  return 0;
}
