#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 100;
const int mod = (int)1e9 + 7;
const long long inv2 = 500000004;
int n, q, p[maxn], ind[maxn], qu[maxn];
long long p2[maxn], ip2[maxn];
vector<pair<int, int> > v;
map<int, int> pos;
void precal() {
  p2[0] = ip2[0] = 1;
  for (auto i = (1); i <= (maxn - 10); ++i)
    p2[i] = p2[i - 1] * 2 % mod, ip2[i] = ip2[i - 1] * inv2 % mod;
}
struct node {
  long long val, lval, rval, k;
} t[maxn << 2];
void pushup(int rt) {
  t[rt].val =
      ((t[rt << 1].val + t[rt << 1 | 1].val) % mod +
       t[rt << 1].lval * t[rt << 1 | 1].rval % mod * ip2[t[rt << 1].k] % mod) %
      mod;
  t[rt].lval =
      (t[rt << 1].lval + t[rt << 1 | 1].lval * p2[t[rt << 1].k] % mod) % mod;
  t[rt].rval =
      (t[rt << 1].rval + t[rt << 1 | 1].rval * ip2[t[rt << 1].k] % mod) % mod;
  t[rt].k = t[rt << 1].k + t[rt << 1 | 1].k;
}
void build(int l = 1, int r = n + q, int rt = 1) {
  if (l == r) {
    if (v[l].second > n) return;
    t[rt].val = 0;
    t[rt].lval = v[l].first;
    t[rt].rval = (v[l].first * inv2) % mod;
    t[rt].k = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  pushup(rt);
}
void update(int pos, int op, int l = 1, int r = n + q, int rt = 1) {
  if (l == r) {
    if (op == 0)
      t[rt].val = t[rt].lval = t[rt].rval = t[rt].k = 0;
    else {
      t[rt].val = 0;
      t[rt].lval = v[pos].first;
      t[rt].rval = (v[pos].first * inv2) % mod;
      t[rt].k = 1;
    }
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(pos, op, l, mid, rt << 1);
  else
    update(pos, op, mid + 1, r, rt << 1 | 1);
  pushup(rt);
}
int main() {
  precal();
  scanf("%d", &n);
  v.push_back({-1, -1});
  for (auto i = (1); i <= (n); ++i) scanf("%d", &p[i]), v.push_back({p[i], i});
  scanf("%d", &q);
  for (auto i = (1); i <= (q); ++i)
    scanf("%d%d", &ind[i], &qu[i]), v.push_back({qu[i], n + i});
  sort(v.begin(), v.end());
  for (auto i = (1); i <= ((int)v.size() - 1); ++i) pos[v[i].second] = i;
  build();
  printf("%lld\n", t[1].val);
  for (auto i = (1); i <= (q); ++i) {
    update(pos[ind[i]], 0);
    pos[ind[i]] = pos[n + i];
    update(pos[ind[i]], 1);
    printf("%lld\n", t[1].val);
  }
}
