#include <bits/stdc++.h>
using namespace std;
int main() {
  std::cout << std::fixed << std::setprecision(20);
  int64_t 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);
  for (int i = 0; i < Q; i++) cin >> B[i] >> C[i];
  sort(A.begin(), A.end());
  int ans = accumulate(A.begin(), A.end(), 0);
  for (int i = 0; i < Q; i++) {
    sort(A.begin(), A.end());
    int64_t s, e;
    if (binary_search(A.begin(), A.end(), B[i])) {
      s = distance(A.begin(), lower_bound(A.begin(), A.end(), B[i]));
      e = distance(A.begin(), upper_bound(A.begin(), A.end(), B[i]));
      for (int j = s; j < e; j++) {
        if (j > A.size() - 1) break;
        A[j] = C[i];
      }
      if (e > A.size() - 1) e = A.size();
      ans += (C[i] - B[i]) * (e - s);
    }
    cout << ans << endl;
  }
}
