#include <bits/stdc++.h>
int main() {
  long long N;
  std::cin >> N;
  std::vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  long long Q;
  std::cin >> Q;
  std::vector<long long> B(Q);
  std::vector<long long> C(Q);
  for (long long i = 0; i < Q; i++) {
    std::cin >> B[i] >> C[i];
  }
  std::sort(A.begin(), A.end());
  long long sum =
      std::accumulate(A.begin(), A.end(), 0.0,
                      [](long long acc, long long i) { return acc + i; });
  for (int i = 0; i < Q; i++) {
    if (std::binary_search(A.begin(), A.end(), B[i])) {
      long long low = std::lower_bound(A.begin(), A.end(), B[i]) - A.begin();
      long long up = std::upper_bound(A.begin(), A.end(), B[i]) - A.begin();
      std::transform(A.begin() + low, A.begin() + up, A.begin() + low,
                     [&](long long a) { return C[i]; });
      std::sort(A.begin(), A.end());
      sum += (C[i] - B[i]) * (up - low);
    }
    std::cout << sum << std::endl;
  }
  return 0;
}
