#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void ash() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  ash();
  int n;
  cin >> n;
  vector<int> a;
  map<int, int> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.emplace_back(x);
    sum = sum + x;
  }
  int q;
  cin >> q;
  sort(a.begin(), a.end());
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    vector<int>::iterator it = lower_bound(a.begin(), a.end(), x);
    vector<int>::iterator it1 = upper_bound(a.begin(), a.end(), x);
    if (it != a.end()) {
      sum = sum - ((*it) * (it1 - it)) + ((it1 - it) * y);
      cout << sum << "\n";
      while (it != it1) {
        *it = y;
        ++it;
      }
    } else
      cout << sum << "\n";
    sort(a.begin(), a.end());
  }
}
