#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 7;
const int maxn = 6e5 + 10;
int n, m, root, topt, cnt, lc[maxn], pos[maxn], v[maxn], val[maxn], now[maxn],
    t;
long long p[maxn], inv;
struct daa {
  int v, id;
} q[maxn];
struct da {
  int lc, rc, si;
  long long l, r, v;
} a[4 * maxn];
inline bool cmp(daa aa, daa bb) { return aa.v < bb.v; }
inline void updata(int n) {
  a[n].si = a[a[n].lc].si + a[a[n].rc].si;
  a[n].v =
      (a[a[n].lc].v * p[a[a[n].rc].si] % mo + a[a[n].lc].l * a[a[n].rc].r % mo +
       a[a[n].rc].v * p[a[a[n].lc].si] % mo) %
      mo;
  a[n].l = (a[a[n].lc].l + a[a[n].rc].l * p[a[a[n].lc].si] % mo) % mo;
  a[n].r = (a[a[n].rc].r + a[a[n].lc].r * p[a[a[n].rc].si] % mo) % mo;
}
void build_tree(int &n, int l, int r) {
  n = ++topt;
  if (l == r) {
    if (q[l].id <= t) {
      now[q[l].id] = l;
      a[n].si = 1;
      a[n].l = q[l].v;
      a[n].r = q[l].v;
      a[n].v = 0;
    }
    return;
  }
  int mid = (l + r) >> 1;
  build_tree(a[n].lc, l, mid);
  build_tree(a[n].rc, mid + 1, r);
  updata(n);
}
void tree_fz(int n, int l, int r, int lc, int k) {
  if (l == r) {
    if (k) {
      a[n].si = 1;
      a[n].l = q[l].v;
      a[n].r = q[l].v;
      a[n].v = 0;
    } else {
      a[n].si = 0;
      a[n].l = 0;
      a[n].r = 0;
      a[n].v = 0;
    }
    return;
  }
  int mid = (l + r) >> 1;
  if (lc <= mid)
    tree_fz(a[n].lc, l, mid, lc, k);
  else
    tree_fz(a[n].rc, mid + 1, r, lc, k);
  updata(n);
}
long long po(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a % mo;
  long long c = po(a, b / 2);
  if (b & 1)
    return c * c % mo * a % mo;
  else
    return c * c % mo;
}
int main() {
  scanf("%d", &n);
  t = n;
  for (int i = 1; i <= n; i++) scanf("%d", &v[i]), q[++cnt] = {v[i], i};
  scanf("%d", &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d", &pos[i], &val[i]), q[++cnt] = {val[i], i + n};
  sort(q + 1, q + cnt + 1, cmp);
  for (int i = 1; i <= cnt; i++) lc[q[i].id] = i;
  p[0] = 1;
  for (int i = 1; i <= cnt; i++) p[i] = p[i - 1] * 2 % mo;
  inv = po(p[n], mo - 2);
  build_tree(root, 1, cnt);
  printf("%lld\n", a[root].v * inv % mo);
  for (int i = 1; i <= m; i++) {
    tree_fz(root, 1, cnt, now[pos[i]], 0);
    now[pos[i]] = lc[n + i];
    tree_fz(root, 1, cnt, now[pos[i]], 1);
    printf("%lld\n", a[root].v * inv % mo);
  }
  return 0;
}
