#include <bits/stdc++.h>
using namespace std;
template <typename T>
class Bit {
 public:
  Bit(int sz) : bit(vector<T>(sz + 1)), size(sz) {}
  T sum(int i) {
    int s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
  void add(int i, T x) {
    while (i <= size) {
      bit[i] += x;
      i += i & -i;
    }
  }

 private:
  Bit();
  vector<T> bit;
  int size;
};
void solve(int N, std::vector<int> A, int Q, std::vector<int> B,
           std::vector<int> C) {
  Bit<long long> cnt{100010};
  for (int i = 0; i < (int)(N); i++) {
    cnt.add(A[i], A[i]);
  }
  for (int i = 0; i < (int)(Q); i++) {
    long long from = (cnt.sum(B[i]) - cnt.sum(B[i] - 1));
    cnt.add(B[i], -from);
    cnt.add(C[i], from * C[i] / B[i]);
    cout << cnt.sum(100011) << endl;
  }
}
int main() {
  int N;
  scanf("%d", &N);
  std::vector<int> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  int Q;
  scanf("%d", &Q);
  std::vector<int> B(Q);
  std::vector<int> C(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d", &B[i]);
    scanf("%d", &C[i]);
  }
  solve(N, std::move(A), Q, std::move(B), std::move(C));
  return 0;
}
