#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10, mod = 1e9 + 7, INF = 1e9;
int n, m, a[N], bin[N], inv[N];
int qpow(int x, int y, int z) {
  int sum = 1;
  while (y) {
    if (y & 1) sum = 1ll * sum * x % z;
    y >>= 1;
    x = 1ll * x * x % z;
  }
  return sum;
}
struct SGT {
  int root, tot, ls[N * 30], rs[N * 30], w[N * 30], lw[N * 30], rw[N * 30],
      size[N * 30];
  void insert(int &k, int l, int r, int x, int y) {
    if (!k) k = ++tot;
    if (l == r) {
      if (y == 1) {
        (w[k] += 1ll * (bin[size[k]] - 1) * inv[size[k] + 1] % mod * x % mod *
                 x % mod) %= mod;
        (lw[k] += 1ll * x * bin[size[k]] % mod) %= mod;
        (rw[k] += 1ll * x * inv[size[k] + 1] % mod) %= mod;
      } else {
        (w[k] -= 1ll * (bin[size[k] - 1] - 1) * inv[size[k]] % mod * x % mod *
                 x % mod) %= mod;
        (lw[k] -= 1ll * x * bin[size[k] - 1] % mod) %= mod;
        (rw[k] -= 1ll * x * inv[size[k]] % mod) %= mod;
      }
      size[k] += y;
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid)
      insert(ls[k], l, mid, x, y);
    else
      insert(rs[k], mid + 1, r, x, y);
    size[k] = size[ls[k]] + size[rs[k]];
    w[k] = (1ll * inv[size[ls[k]]] * lw[ls[k]] % mod * rw[rs[k]] % mod +
            w[ls[k]] + w[rs[k]]) %
           mod;
    lw[k] = (lw[ls[k]] + 1ll * lw[rs[k]] * bin[size[ls[k]]] % mod) % mod;
    rw[k] = (rw[ls[k]] + 1ll * rw[rs[k]] * inv[size[ls[k]]] % mod) % mod;
  }
} T;
int main() {
  bin[0] = 1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) bin[i] = bin[i - 1] * 2 % mod;
  inv[n] = qpow(bin[n], mod - 2, mod);
  for (int i = n; i; i--) inv[i - 1] = 2 * inv[i] % mod;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), T.insert(T.root, 1, INF, a[i], 1);
  printf("%d\n", T.w[1]);
  scanf("%d\n", &m);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    T.insert(T.root, 1, INF, a[x], -1);
    a[x] = y;
    T.insert(T.root, 1, INF, a[x], 1);
    printf("%d\n", (T.w[1] + mod) % mod);
  }
  return 0;
}
