#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inv2 = 500000004;
const int N = 3e5 + 7;
int n, q, cnt, now;
int p[N], id[N], to[N], sz[N << 3];
pair<int, int> lsh[N << 1];
long long pw[N], pwinv[N], sum[N << 3], f[N << 3], g[N << 3];
void insert(int p, int id, int add, int l, int r) {
  sz[p] += add;
  if (l == r)
    return g[p] += add * lsh[id].first, f[p] += add * lsh[id].first, void();
  const int mid = l + r >> 1;
  if (id <= mid)
    insert(p << 1, id, add, l, mid);
  else
    insert(p << 1 | 1, id, add, mid + 1, r);
  f[p] = (f[p << 1] + f[p << 1 | 1] * pw[sz[p << 1]]) % mod;
  g[p] = (g[p << 1] + g[p << 1 | 1] * pwinv[sz[p << 1]]) % mod;
  sum[p] = (sum[p << 1] + sum[p << 1 | 1] +
            f[p << 1] * g[p << 1 | 1] % mod * pwinv[sz[p << 1]]) %
           mod;
}
inline int read(register int x = 0, register char ch = getchar(),
                register int f = 0) {
  for (; !isdigit(ch); ch = getchar()) f = ch == '-';
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
  return f ? -x : x;
}
int main() {
  n = read();
  for (int i = pw[0] = pwinv[0] = 1; i <= n; ++i)
    pw[i] = pw[i - 1] * 2 % mod, pwinv[i] = pwinv[i - 1] * inv2 % mod;
  for (int i = 1; i <= n; ++i)
    p[i] = read(), ++cnt, lsh[cnt] = make_pair(p[i], cnt);
  q = read();
  for (int i = 1; i <= q; ++i)
    id[i] = read(), to[i] = read(), ++cnt, lsh[cnt] = make_pair(to[i], cnt);
  sort(lsh + 1, lsh + cnt + 1);
  for (int i = 1; i <= n; ++i)
    ++now, insert(1,
                  p[i] = lower_bound(lsh + 1, lsh + cnt + 1,
                                     make_pair(p[i], now)) -
                         lsh,
                  1, 1, cnt);
  printf("%lld\n", sum[1] * inv2 % mod);
  for (int i = 1; i <= q; ++i)
    ++now, insert(1, p[id[i]], -1, 1, cnt),
        insert(1,
               p[id[i]] =
                   lower_bound(lsh + 1, lsh + cnt + 1, make_pair(to[i], now)) -
                   lsh,
               1, 1, cnt),
        printf("%lld\n", sum[1] * inv2 % mod);
  return 0;
}
