#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
vector<int> ans;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  ll total = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    total += a[i];
  }
  sort(a.begin(), a.end());
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    int left = lower_bound(a.begin(), a.end(), b) - a.begin();
    int right = lower_bound(a.begin(), a.end(), b + 1) - a.begin();
    if (a[left] != b) {
      ans.push_back(total);
      continue;
    }
    if (a[right] == b) right++;
    int sa = c - b;
    total += sa * (right - left);
    ans.push_back(total);
    for (int j = left; j < right; j++) {
      a[j] = c;
    }
    sort(a.begin(), a.end());
  }
  for (int i = 0; i < (ans.size()); ++i) cout << ans[i] << endl;
  return 0;
}
