#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> vec;
  vector<int>::iterator it;
  int msum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    msum += x;
    vec.push_back(x);
  }
  sort(vec.begin(), vec.end());
  int t;
  cin >> t;
  while (t--) {
    int v, val;
    cin >> v >> val;
    it = find(vec.begin(), vec.end(), v);
    if (it == vec.end())
      cout << msum << endl;
    else {
      while (*it == v) {
        msum -= *it;
        *it = val;
        msum += *it;
        ++it;
      }
      cout << msum << endl;
    }
  }
  return 0;
}
