#include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
struct node {
  int x;
  int id;
} a[600005];
int qq[300005];
int pos[600005];
int n;
long long pw[600005];
long long inv[600005];
long long val[600005 << 2];
long long lv[600005 << 2];
long long rv[600005 << 2];
long long c[600005 << 2];
long long qpow(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * a % p;
    a = a * a % p;
    n >>= 1;
  }
  return res;
}
bool cmp(node a, node b) {
  if (a.x != b.x)
    return a.x < b.x;
  else
    return a.id < b.id;
}
void pushup(int rt) {
  val[rt] = (val[rt << 1] + val[rt << 1 | 1] +
             lv[rt << 1] * rv[rt << 1 | 1] % p * inv[c[rt << 1]] % p) %
            p;
  lv[rt] = (lv[rt << 1] + lv[rt << 1 | 1] * pw[c[rt << 1]] % p) % p;
  rv[rt] = (rv[rt << 1] + rv[rt << 1 | 1] * inv[c[rt << 1]] % p) % p;
  c[rt] = c[rt << 1] + c[rt << 1 | 1];
}
void build(int l, int r, int rt) {
  if (l == r) {
    if (a[l].id <= n) {
      val[rt] = 0;
      lv[rt] = a[l].x;
      rv[rt] = a[l].x * inv[1] % p;
      c[rt] = 1;
    }
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  pushup(rt);
}
void update(int l, int r, int rt, int x, int v) {
  if (l == r && l == x) {
    if (v == -1) {
      val[rt] = 0;
      lv[rt] = 0;
      rv[rt] = 0;
      c[rt] = 0;
    } else {
      val[rt] = 0;
      lv[rt] = a[l].x;
      rv[rt] = a[l].x * inv[1] % p;
      c[rt] = 1;
    }
    return;
  }
  int m = (l + r) >> 1;
  if (x <= m)
    update(l, m, rt << 1, x, v);
  else
    update(m + 1, r, rt << 1 | 1, x, v);
  pushup(rt);
}
void work() {
  long long inv2 = qpow(2, p - 2);
  pw[0] = 1;
  inv[0] = 1;
  for (int i = 1; i <= 600000; i++) {
    pw[i] = pw[i - 1] * 2 % p;
    inv[i] = inv[i - 1] * inv2 % p;
  }
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i].x);
    a[i].id = i;
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &qq[i], &a[n + i].x);
    a[n + i].id = n + i;
  }
  sort(a + 1, a + n + q + 1, cmp);
  for (int i = 1; i <= n + q; i++) {
    pos[a[i].id] = i;
  }
  build(1, n + q, 1);
  printf("%lld\n", val[1]);
  for (int i = 1; i <= q; i++) {
    update(1, n + q, 1, pos[qq[i]], -1);
    pos[qq[i]] = pos[n + i];
    update(1, n + q, 1, pos[qq[i]], 1);
    printf("%lld\n", val[1]);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  while (T--) {
    work();
  }
}
