#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const long long MOD = 1000000007;
template <typename T>
class Treap {
 public:
  Treap() : root_(nullptr) {}
  void Insert(long long k, T v) { root_ = Insert(root_, k, v, rand()); }
  void Update(long long k, T v) {
    root_ = Erase(root_, k);
    root_ = Insert(root_, k, v, rand());
  }
  void Shift(long long l, long long r) { root_ = Shift(root_, l, r + 1); }
  T Min(long long l, long long r) { return Min(root_, l, r + 1); }
  T Max(long long l, long long r) { return Max(root_, l, r + 1); }
  T Sum(long long l, long long r) { return Sum(root_, l, r + 1); }

 private:
  static const T kInf = 1000000001;
  struct Node {
    Node(long long v, double p)
        : val(v), pri(p), cnt(1), sum(v), min(v), max(v) {
      lch = nullptr;
      rch = nullptr;
    }
    T val;
    Node *lch;
    Node *rch;
    double pri;
    long long cnt;
    T sum;
    T min;
    T max;
  };
  long long Count(Node *t) { return !t ? 0 : t->cnt; }
  long long Sum(Node *t) { return !t ? 0 : t->sum; }
  long long Min(Node *t) { return !t ? kInf : t->min; }
  long long Max(Node *t) { return !t ? -kInf : t->max; }
  Node *Update(Node *t) {
    t->cnt = Count(t->lch) + Count(t->rch) + 1;
    t->sum = Sum(t->lch) + Sum(t->rch) + t->val;
    t->min = min(min(Min(t->lch), Min(t->rch)), t->val);
    t->max = max(max(Max(t->lch), Max(t->rch)), t->val);
    return t;
  }
  Node *Merge(Node *l, Node *r) {
    if (!l) {
      return r;
    } else if (!r) {
      return l;
    }
    if (l->pri > r->pri) {
      l->rch = Merge(l->rch, r);
      return Update(l);
    } else {
      r->lch = Merge(l, r->lch);
      return Update(r);
    }
  }
  pair<Node *, Node *> Split(Node *t, long long k) {
    if (!t) return make_pair(nullptr, nullptr);
    if (k <= Count(t->lch)) {
      auto s = Split(t->lch, k);
      t->lch = s.second;
      return make_pair(s.first, Update(t));
    } else {
      auto s = Split(t->rch, k - Count(t->lch) - 1);
      t->rch = s.first;
      return make_pair(Update(t), s.second);
    }
  }
  Node *Insert(Node *t, long long k, long long val, double pri) {
    auto s = Split(t, k);
    Node *n = new Node(val, pri);
    return Merge(Merge(s.first, n), s.second);
  }
  Node *Erase(Node *t, long long k) {
    auto s = Split(t, k);
    auto u = Split(s.second, 1);
    delete u.first;
    return Merge(s.first, u.second);
  }
  Node *Shift(Node *t, long long l, long long r) {
    auto c = Split(t, r);
    auto b = Split(c.first, r - 1);
    auto a = Split(b.first, l);
    return Merge(Merge(a.first, b.second), Merge(a.second, c.second));
  }
  long long Min(Node *t, long long l, long long r) {
    if (!t) return kInf;
    if (l <= 0 && Count(t) <= r) return Min(t);
    if (r <= 0 || Count(t) <= l) return kInf;
    long long l_min = Min(t->lch, l, r);
    long long r_min = Min(t->rch, l - Count(t->lch) - 1, r - Count(t->lch) - 1);
    long long ans = min(l_min, r_min);
    if (l <= Count(t->lch) && Count(t->lch) < r) {
      ans = min(ans, t->val);
    }
    return ans;
  }
  long long Max(Node *t, long long l, long long r) {
    if (!t) return -kInf;
    if (l <= 0 && Count(t) <= r) return Max(t);
    if (r <= 0 || Count(t) <= l) return -kInf;
    long long l_max = Max(t->lch, l, r);
    long long r_max = Max(t->rch, l - Count(t->lch) - 1, r - Count(t->lch) - 1);
    long long ans = max(l_max, r_max);
    if (l <= Count(t->lch) && Count(t->lch) < r) {
      ans = max(ans, t->val);
    }
    return ans;
  }
  long long Sum(Node *t, long long l, long long r) {
    if (!t) return 0;
    if (l <= 0 && Count(t) <= r) return Sum(t);
    if (r <= 0 || Count(t) <= l) return 0;
    long long l_max = Sum(t->lch, l, r);
    long long r_max = Sum(t->rch, l - Count(t->lch) - 1, r - Count(t->lch) - 1);
    long long ans = l_max + r_max;
    if (l <= Count(t->lch) && Count(t->lch) < r) {
      ans = ans + t->val;
    }
    return ans;
  }
  Node *root_;
};
void solve(long long N, std::vector<long long> A, long long Q,
           std::vector<long long> B, std::vector<long long> C) {
  map<long long, long long> m;
  for (int i = 0; i < (int)(N); i++) {
    if (m.find(A[i]) != m.end()) {
      m[A[i]]++;
    } else {
      m[A[i]] = 1;
    }
  }
  Treap<long long> treap;
  for (int i = 0; i < (int)(1e5); i++) {
    treap.Insert(i, 0);
  }
  for (auto it = m.begin(); it != m.end(); it++) {
    treap.Update(it->first, it->first * it->second);
  }
  for (int i = 0; i < (int)(Q); i++) {
    long long count = treap.Sum(B[i], B[i]) / B[i];
    treap.Update(B[i], 0);
    long long cur = treap.Sum(C[i], C[i]);
    treap.Update(C[i], cur + C[i] * count);
    cout << treap.Sum(0, 1e5 - 1) << endl;
  }
}
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  long long Q;
  scanf("%lld", &Q);
  std::vector<long long> B(Q);
  std::vector<long long> C(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &B[i]);
    scanf("%lld", &C[i]);
  }
  solve(N, std::move(A), Q, std::move(B), std::move(C));
  return 0;
}
