#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, Q;
  cin >> N;
  vector<int> A(N);
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  sort(A.begin(), A.end());
  cin >> Q;
  while (Q--) {
    int B, C;
    cin >> B >> C;
    int r = lower_bound(A.begin(), A.end(), B) - A.begin();
    if (A[r] != B) {
      cout << sum << endl;
      continue;
    }
    int l = upper_bound(A.begin(), A.end(), B) - A.begin();
    sum += (l - r) * (C - B);
    cout << sum << endl;
    for (int i = r; i < l; i++) {
      A[i] = C;
    }
    if (r >= 1 && A[l - 1] > A[l] || A[r] < A[r - 1]) {
      sort(A.begin(), A.end());
    }
  }
  return 0;
}
