#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, q;
  int sum = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b.at(i);
    cin >> c.at(i);
  }
  sort(a.begin(), a.end());
  sum = accumulate(a.begin(), a.end(), 0);
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (b.at(i) > a.at(j)) {
        continue;
      } else if (b.at(i) == a.at(j)) {
        a.at(j) = c.at(i);
        if (b < c) {
          sum = sum + (c.at(i) - b.at(i));
        } else if (b.at(i) > c.at(i)) {
          sum = sum - (b.at(i) - c.at(i));
        }
      } else {
        break;
      }
    }
    cout << sum << endl;
    sort(a.begin(), a.end());
  }
  return 0;
}
