#include <bits/stdc++.h>
using namespace std;
int A[100010];
int B[100010];
int C[100010];
int main() {
  int N, Q, Bi, Ci;
  long long sum = 0;
  int tmp_a;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  sort(A, A + N);
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (int i = 0; i < Q; i++) {
    tmp_a = *std::lower_bound(A, A + N, B[i]) - 1;
    cout << endl << tmp_a << endl;
    if (A[tmp_a] == B[i]) {
      sum += C[i] - A[tmp_a];
      A[tmp_a] = C[i];
    }
    cout << sum << endl;
  }
}
