#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  long long total = 0;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    total += a[i];
  }
  sort(a.begin(), a.end());
  int q;
  cin >> q;
  vector<int> t;
  while (q > 0) {
    int b, c;
    cin >> b >> c;
    auto be = lower_bound(a.begin(), a.end(), b);
    auto la = upper_bound(a.begin(), a.end(), b);
    int cnt = 0;
    for (auto itr = be; itr != la; ++itr) {
      *itr = c;
      cnt++;
    }
    total += (c - b) * cnt;
    t.push_back(total);
    q--;
  }
  for (int i = 0; i < (t.size()); i++) cout << t[i] << endl;
  return 0;
}
