#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, inv2 = (mod + 1) / 2;
inline int read() {
  int s = 0, w = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') w |= (ch == '-'), ch = getchar();
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return w ? -s : s;
}
inline int Mul(int a, int b) { return (long long)a * b % mod; }
inline int Add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int qpow(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = Mul(a, a))
    if (b & 1) res = Mul(res, a);
  return res;
}
int n;
int bin[310000], nbin[310000];
struct node {
  int id, val, yw;
} Q[310000 << 1];
int q;
int ys[310000 << 1];
inline bool cmp1(const node &a, const node &b) { return a.val < b.val; }
inline bool cmp2(const node &a, const node &b) { return a.id < b.id; }
int v1[310000 << 3], v2[310000 << 3], cnt[310000 << 3], an[310000 << 3];
inline void up(int u) {
  cnt[u] = cnt[(u << 1)] + cnt[(u << 1 | 1)];
  v1[u] = Add(v1[(u << 1)], Mul(v1[(u << 1 | 1)], bin[cnt[(u << 1)]]));
  v2[u] = Add(v2[(u << 1)], Mul(v2[(u << 1 | 1)], nbin[cnt[(u << 1)]]));
  an[u] = Add(Add(an[(u << 1)], an[(u << 1 | 1)]),
              Mul(Mul(v1[(u << 1)], v2[(u << 1 | 1)]), nbin[cnt[(u << 1)]]));
  return;
}
void modify(int u, int l, int r, int pos, int vv1, int vv2, int opt) {
  if (l == r) {
    if (opt)
      cnt[u] = 1, v1[u] = vv1, v2[u] = vv2, an[u] = 0;
    else
      cnt[u] = 0, v1[u] = v2[u] = an[u];
    return;
  }
  int mid = l + r >> 1;
  if (pos <= mid)
    modify((u << 1), l, mid, pos, vv1, vv2, opt);
  else
    modify((u << 1 | 1), mid + 1, r, pos, vv1, vv2, opt);
  return up(u), void();
}
int nw[310000];
int main() {
  n = (read());
  for (int i = 1, val; i <= n; ++i) val = (read()), Q[i] = (node){i, val, 0};
  bin[0] = nbin[0] = 1;
  for (int i = 1; i <= n; ++i)
    bin[i] = (bin[i - 1] << 1) % mod, nbin[i] = Mul(nbin[i - 1], inv2);
  q = (read());
  for (int i = 1, p, x; i <= q; ++i) {
    p = (read()), x = (read());
    Q[i + n] = (node){i + n, x, p};
  }
  sort(Q + 1, Q + n + q + 1, cmp1);
  for (int i = 1; i <= n + q; ++i) ys[Q[i].id] = i;
  sort(Q + 1, Q + n + q + 1, cmp2);
  for (int i = 1; i <= n; ++i)
    modify(1, 1, n + q, ys[i], Mul(Q[i].val, 2), Mul(Q[i].val, nbin[2]), 1),
        nw[i] = ys[i];
  printf("%d\n", an[1]);
  for (int i = 1, p, k; i <= q; ++i) {
    p = Q[i + n].yw, k = Q[i + n].val;
    modify(1, 1, n + q, nw[p], 0, 0, 0);
    modify(1, 1, n + q, ys[i + n], Mul(k, 2), Mul(k, nbin[2]), 1);
    nw[p] = ys[i + n];
    printf("%d\n", an[1]);
  }
  return 0;
}
