#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.at(i);
  }
  sort(A.begin(), A.end());
  cin >> Q;
  vector<int> sum(Q + 1);
  vector<int> b(Q);
  vector<int> c(Q);
  for (int i = 0; i < Q; i++) {
    cin >> b.at(i) >> c.at(i);
    for (int j = 0; j < N; j++) {
      if (b.at(i) == A.at(j)) {
        A.at(j) = c.at(i);
      } else if (b.at(i) < A.at(j)) {
        break;
      }
    }
    for (int k = 0; k < N; k++) {
      sum.at(i) += A.at(k);
      if (k == N - 1) {
        cout << sum.at(i) << endl;
      }
    }
  }
}
