#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
int p[N];
long long p2[N];
long long invp2[N];
long long a[N];
long long sum[N];
int n, q;
int T[3 * N], tot;
int f[3 * N], c;
int pos[N], x[N];
long long pre[N];
map<int, int> mp;
struct Tree {
  int l, r;
  long long suml, sumr;
  long long ans;
  int cnt;
} tree[10 * N];
void PushUp(int i) {
  tree[i].cnt = tree[i * 2].cnt + tree[i * 2 + 1].cnt;
  tree[i].suml =
      (tree[i * 2].suml + tree[i * 2 + 1].suml * p2[tree[i * 2].cnt]) % mod;
  tree[i].sumr =
      (tree[i * 2].sumr * p2[tree[i * 2 + 1].cnt] + tree[i * 2 + 1].sumr) % mod;
  tree[i].ans = (tree[i * 2].ans * p2[tree[i * 2 + 1].cnt] +
                 tree[i * 2 + 1].ans * p2[tree[i * 2].cnt] +
                 tree[i * 2].suml * tree[i * 2 + 1].sumr) %
                mod;
}
void Build(int i, int l, int r) {
  tree[i].l = l;
  tree[i].r = r;
  if (l == r) return;
  int mid = (tree[i].l + tree[i].r) / 2;
  Build(i * 2, l, mid);
  Build(i * 2 + 1, mid + 1, r);
}
int Pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b % 2) ans = 1ll * ans * a % mod;
    a = (1ll * a * a) % mod;
    b /= 2;
  }
  return ans;
}
void Add(int i, int pos, int x) {
  if (tree[i].l == tree[i].r) {
    tree[i].cnt += x;
    tree[i].suml = 1ll * f[pos] * (p2[tree[i].cnt] - 1) % mod;
    tree[i].sumr = 1ll * f[pos] * (p2[tree[i].cnt] - 1) % mod;
    tree[i].ans = 1ll * f[pos] * f[pos] % mod * pre[tree[i].cnt] % mod;
    return;
  }
  int mid = (tree[i].l + tree[i].r) / 2;
  if (pos <= mid)
    Add(i * 2, pos, x);
  else
    Add(i * 2 + 1, pos, x);
  PushUp(i);
}
void print() {
  for (int i = 1; i <= 10; i++)
    printf("[%d %d] %lld %lld %lld\n", tree[i].l, tree[i].r, tree[i].suml,
           tree[i].sumr, tree[i].ans);
  printf("----------------------\n");
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    T[++tot] = p[i];
  }
  p2[0] = 1;
  for (int i = 1; i <= n; i++) {
    p2[i] = (p2[i - 1] * 2) % mod;
    pre[i] = (pre[i - 1] + 1ll * p2[i - 2] * (i - 1)) % mod;
    invp2[i] = Pow(p2[i], mod - 2);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &pos[i], &x[i]);
    T[++tot] = x[i];
  }
  sort(T + 1, T + 1 + tot);
  for (int i = 1; i <= tot; i++)
    if (i == 1 || T[i] != T[i - 1]) {
      c++;
      mp[T[i]] = c;
      f[c] = T[i];
    }
  for (int i = 1; i <= n; i++) p[i] = mp[p[i]];
  for (int i = 1; i <= q; i++) x[i] = mp[x[i]];
  Build(1, 1, c);
  for (int i = 1; i <= n; i++) Add(1, p[i], 1);
  printf("%lld\n", tree[1].ans * invp2[n] % mod);
  for (int i = 1; i <= q; i++) {
    Add(1, p[pos[i]], -1);
    Add(1, x[i], 1);
    printf("%lld\n", tree[1].ans * invp2[n] % mod);
    p[pos[i]] = x[i];
  }
}
