#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  fastio();
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    replace(a, a + n, x, y);
    long long s = 0;
    for (long long i = 0; i < n; ++i) {
      s = s + a[i];
    }
    cout << s << endl;
  }
  return 0;
}
