#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int search(vector<int>& a, int n, int key, int c) {
  int left = 0;
  int right = n;
  while (left < right) {
    int mid = (left + right) / 2;
    if (a[mid] == key) {
      a[mid] = c;
      return 1;
    } else if (a[mid] > key)
      right = mid;
    else
      left = mid + 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < (q); i++) cin >> b[i] >> c[i];
  vector<ll> s(q, 0);
  bool flag = true;
  for (int i = 0; i < q; i++) {
    while (flag) {
      sort(a.begin(), a.end());
      if (search(a, n, b[i], c[i]))
        flag = true;
      else
        break;
    }
    s[i] = accumulate(a.begin(), a.end(), 0);
    cout << s[i] << endl;
  }
  return 0;
}
