#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> B.at(i) >> C.at(i);
  }
  for (int i = 0; i < Q; ++i) {
    vector<int>::iterator it_s = lower_bound(A.begin(), A.end(), B.at(i));
    vector<int>::iterator it_e = upper_bound(A.begin(), A.end(), B.at(i));
    for (vector<int>::iterator itr = it_s; itr < it_e; ++itr) {
      *itr = C.at(i);
    }
    cout << accumulate(A.begin(), A.end(), 0) << endl;
  }
}
