#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, sum = 0, q;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
  }
  sort(v.begin(), v.end());
  cin >> q;
  vector<pair<long long, long long>> qu(q);
  for (long long i = 0; i < q; i++) {
    long long x, y;
    cin >> x >> y;
    qu[i] = make_pair(x, y);
  }
  for (long long i = 0; i < q; i++) {
    for (long long j = 0; j < n; j++) {
      if (v[j] == qu[i].first) {
        sum = sum + qu[i].second - qu[i].first;
        v[j] = qu[i].second;
      } else if (v[j] > qu[i].first)
        break;
    }
    cout << sum << "\n";
  }
  return 0;
}
