#include <bits/stdc++.h>
using namespace std;
const int MAXN = 600005;
const long long MOD = 1000000007;
int n, q, tot, dat[MAXN], a[MAXN], pos[MAXN], x[MAXN], cnt[MAXN * 4];
long long val[MAXN * 4], f[MAXN * 4], g[MAXN * 4], pw[MAXN];
unordered_map<int, int> mp;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    (x *= 10) += ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline long long fast_power(long long x, long long k) {
  long long res = 1;
  while (k) {
    if (k & 1) (res *= x) %= MOD;
    (x *= x) %= MOD;
    k >>= 1;
  }
  return res;
}
inline void push_up(int p, int l, int r) {
  cnt[p] = cnt[p << 1] + cnt[p << 1 | 1];
  val[p] = (val[p << 1] + val[p << 1 | 1] + f[p << 1] * g[p << 1 | 1]) % MOD;
  f[p] = (f[p << 1 | 1] + f[p << 1] * pw[cnt[p << 1 | 1]]) % MOD;
  g[p] = (g[p << 1] + g[p << 1 | 1] * pw[cnt[p << 1]]) % MOD;
}
void upd(int p, int l, int r, int pos, long long v) {
  if (l == r) {
    if (v == 1) cnt[p] = 1, val[p] = 0, f[p] = g[p] = dat[l] * pw[1] % MOD;
    if (v == -1) cnt[p] = 0, val[p] = 0, f[p] = g[p] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    upd(p << 1, l, mid, pos, v);
  else
    upd(p << 1 | 1, mid + 1, r, pos, v);
  push_up(p, l, r);
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = dat[++tot] = read();
  q = read();
  for (int i = 1; i <= q; i++) pos[i] = read(), x[i] = dat[++tot] = read();
  sort(dat + 1, dat + tot + 1);
  for (int i = 1, p; i <= n; i++) {
    p = lower_bound(dat + 1, dat + tot + 1, a[i]) - dat;
    a[i] = p + mp[p]++;
  }
  for (int i = 1, p; i <= q; i++) {
    p = lower_bound(dat + 1, dat + tot + 1, x[i]) - dat;
    x[i] = p + mp[p]++;
  }
  pw[0] = 1;
  pw[1] = fast_power(2, MOD - 2);
  for (int i = 2; i <= n; i++) pw[i] = pw[i - 1] * pw[1] % MOD;
  for (int i = 1; i <= n; i++) upd(1, 1, tot, a[i], 1);
  printf("%lld\n", val[1]);
  for (int i = 1; i <= q; i++) {
    upd(1, 1, tot, a[pos[i]], -1);
    a[pos[i]] = x[i];
    upd(1, 1, tot, a[pos[i]], 1);
    printf("%lld\n", val[1]);
  }
  return 0;
}
