#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  long long sum = 0;
  vector<int> A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  sort(A.begin(),A.end());
  int Q;
  cin >> Q;
  
  vector<vector<int>> data(Q, vector<int>(2));
  for (int i = 0; i < Q; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> data.at(i).at(j); 
    }
  }
  for (int i = 0; i < Q; i++) {
    auto iter = lower_bound(A.begin(),A.end(),data[i][0]);  
    if (iter != data.end() && *iter == data[i][0]) {
      int Z = distance(vec.begin(), iter);
      sum = sum - A[Z];
      A[Z] = data[i][0];
      sum += A[Z];
      cout << sum << endl;
    }     
  }
}