#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cin >> Q;
  vector<int> B(Q);
  vector<int> C(Q);
  int ans = 0;
  for (int k = 0; k < Q; k++) {
    cin >> B[k] >> C[k];
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
      if (A[i] == B[k]) {
        A[i] = C[k];
        if (A[i + 1] > B[k]) {
          ans += A[i] + A[i + 1];
          break;
        }
      }
      ans += A[i];
    }
    cout << ans << endl;
    ans *= 0;
  }
}
