#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A;
  for (int n = 0; n < N; ++n) {
    int a;
    cin >> a;
    A.push_back(a);
  }
  sort(A.begin(), A.end());
  int Q;
  cin >> Q;
  vector<long> ans;
  for (int n = 0; n < Q; ++n) {
    int B, C;
    cin >> B;
    cin >> C;
    auto i = equal_range(A.begin(), A.end(), B);
    fill(i.first, i.second, C);
    long a = accumulate(A.begin(), A.end(), 0);
    ans.push_back(a);
  }
  for (auto& a : ans) {
    cout << a << endl;
  }
}
