#include <bits/stdc++.h>
using namespace std;
const long long INF = 1001001001;
const long long LINF = 1001001001001001001;
const long long D4[] = {0, 1, 0, -1, 0};
const long long D8[] = {0, 1, 1, 0, -1, -1, 1, -1, 0};
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
long long N;
vector<long long> A;
long long Q;
vector<long long> B;
vector<long long> C;
void solve();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> N;
  A = vector<long long>(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  cin >> Q;
  B = vector<long long>(Q);
  C = vector<long long>(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> B[i];
    cin >> C[i];
  }
  solve();
}
struct BinaryIndexedTree {
  int sz;
  vector<long long> data;
  BinaryIndexedTree(int sz) : sz(sz) { data.assign(sz, 0); }
  void add(int x, int val) {
    while (x < sz) data[x] += val, x |= x + 1;
  }
  long long sum(int to) {
    to = min(to, sz - 1);
    long long ret = 0;
    while (to >= 0) ret += data[to], to = (to & (to + 1)) - 1;
    return ret;
  }
  long long sum(int from, int to) {
    if (from > to) return 0;
    return sum(to) - sum(from - 1);
  }
};
void solve() {
  BinaryIndexedTree bit(100010);
  for (long long i = 0; i < (N); ++i) {
    bit.add(A[i], A[i]);
  }
  for (long long i = 0; i < (Q); ++i) {
    long long cnt = (bit.sum(B[i]) - bit.sum(B[i] - 1)) / B[i];
    bit.add(B[i], -B[i] * cnt);
    bit.add(C[i], C[i] * cnt);
    cout << bit.sum(100000) << endl;
  }
}
