#include <stdint.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

template <typename T>
class Treap {
 public:
  Treap() : root_(nullptr) {}
  void Insert(ll k, T v) {
    root_ = Insert(root_, k, v, rand());
  }
  void Update(ll k, T v) {
    root_ = Erase(root_, k);
    root_ = Insert(root_, k, v, rand());
  }
  void Shift(ll l, ll r) {
    root_ = Shift(root_, l, r + 1);
  }
  T Min(ll l, ll r) {
    return Min(root_, l, r + 1);
  }
  T Max(ll l, ll r) {
    return Max(root_, l, r + 1);
  }
  T Sum(ll l, ll r) {
    return Sum(root_, l, r + 1);
  }

 private:
  static const T kInf = 1000000001;

  struct Node {
    Node(ll 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;
    ll cnt;
    T sum;
    T min;
    T max;
  };

  ll Count(Node *t) {
    return !t ? 0 : t->cnt;
  }
  ll Sum(Node *t) {
    return !t ? 0 : t->sum;
  }
  ll Min(Node *t) {
    return !t ? kInf : t->min;
  }
  ll 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, ll k) {  // [0, k), [k, n)
    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, ll k, ll 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, ll 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, ll l, ll 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));
  }
  ll Min(Node *t, ll l, ll r) {
    if (!t)
      return kInf;
    if (l <= 0 && Count(t) <= r)
      return Min(t);
    if (r <= 0 || Count(t) <= l)
      return kInf;
    ll l_min = Min(t->lch, l, r);
    ll r_min = Min(t->rch, l - Count(t->lch) - 1, r - Count(t->lch) - 1);
    ll ans = min(l_min, r_min);
    if (l <= Count(t->lch) && Count(t->lch) < r) {
      ans = min(ans, t->val);
    }
    return ans;
  }
  ll Max(Node *t, ll l, ll r) {
    if (!t)
      return -kInf;
    if (l <= 0 && Count(t) <= r)
      return Max(t);
    if (r <= 0 || Count(t) <= l)
      return -kInf;
    ll l_max = Max(t->lch, l, r);
    ll r_max = Max(t->rch, l - Count(t->lch) - 1, r - Count(t->lch) - 1);
    ll ans = max(l_max, r_max);
    if (l <= Count(t->lch) && Count(t->lch) < r) {
      ans = max(ans, t->val);
    }
    return ans;
  }
  ll Sum(Node *t, ll l, ll r) {
    if (!t)
      return 0;
    if (l <= 0 && Count(t) <= r)
      return Sum(t);
    if (r <= 0 || Count(t) <= l)
      return 0;
    ll l_max = Sum(t->lch, l, r);
    ll r_max = Sum(t->rch, l - Count(t->lch) - 1, r - Count(t->lch) - 1);
    ll 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<ll, ll> m;
  REP(i, N) {
    if (m.find(A[i]) != m.end()) {
      m[A[i]]++;
    } else {
      m[A[i]] = 1;
    }
  }
  Treap<ll> treap;
  REP(i, 1e5 + 10) {
    treap.Insert(i, 0);
  }
  for (auto it = m.begin(); it != m.end(); it++) {
    treap.Update(it->first, it->first * it->second);
  }
  REP(i, Q) {
    ll count = treap.Sum(B[i], B[i]) / B[i];
    treap.Update(B[i], 0);
    ll cur = treap.Sum(C[i], C[i]);
    treap.Update(C[i], cur + C[i] * count);
    cout << treap.Sum(0, 1e5) << 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;
}


Measured memory_bytes: 17504