#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, i, b, c, l, u, s = 0, q;
  vector<int> v;
  cin >> n;
  long long a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s = s + a[i];
    v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  cin >> q;
  while (q--) {
    cin >> b >> c;
    auto u = upper_bound(v.begin(), v.end(), b);
    auto l = lower_bound(v.begin(), v.end(), b);
    for (i = l - v.begin(); i < u - v.begin(); i++) {
      v[i] = c;
    }
    s = s + (u - l) * c - (u - l) * b;
    cout << s << endl;
  }
}
int main() {
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
