#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
    v.push_back(a);
  }
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    sort(v.begin(), v.end());
    auto x = lower_bound(v.begin(), v.end(), a);
    auto y = upper_bound(v.begin(), v.end(), a);
    for (auto it = x; it < y; it++) {
      *it = b;
    }
    sum += ((y - x) * b);
    sum -= ((y - x) * a);
    cout << sum << endl;
  }
}
