#include <bits/stdc++.h>
using namespace std;
int Gcd(int a, int b) {
  if (b == 0) return a;
  return Gcd(b, a % b);
}
int Lcm(int a, int b) { return a / Gcd(a, b) * b; }
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 6e5 + 10;
const long long mod = 1e9 + 7;
long long I[maxn];
int p[maxn], q[maxn];
struct P {
  long long val, id;
  bool operator<(const P& rhs) const { return val < rhs.val; }
} a[maxn];
struct node {
  long long ans, c;
  long long sl, sr;
} t[maxn << 2];
void modify(int id, int l, int r, int x, int c) {
  if (l == r) {
    t[id].c = c;
    t[id].ans = t[id].sl = t[id].sr = 0;
    if (c) t[id].sl = t[id].sr = 1ll * I[1] * a[x].val % mod;
    return;
  }
  int mid = (l + r) >> 1, ls = id << 1, rs = id << 1 | 1;
  if (x <= mid)
    modify(ls, l, mid, x, c);
  else
    modify(rs, mid + 1, r, x, c);
  t[id].c = t[ls].c + t[rs].c;
  t[id].sl = (1ll * t[ls].sl * I[t[rs].c] + t[rs].sl) % mod;
  t[id].sr = (1ll * t[rs].sr * I[t[ls].c] + t[ls].sr) % mod;
  t[id].ans = (t[ls].ans + t[rs].ans + 1ll * t[ls].sl * t[rs].sr) % mod;
}
int main() {
  I[0] = 1, I[1] = (mod + 1) / 2;
  for (int i = 2; i < maxn; i++) {
    I[i] = 1ll * I[1] * I[i - 1] % mod;
  }
  int n = read();
  for (int i = 1; i <= n; i++) {
    a[i].val = read();
    a[i].id = i;
    p[i] = i;
  }
  int m = read();
  for (int i = 1; i <= m; i++) {
    q[i] = read();
    a[n + i].val = read();
    a[n + i].id = n + i;
    p[n + i] = n + i;
  }
  sort(a + 1, a + n + m + 1);
  for (int i = 1; i <= n + m; i++) {
    p[a[i].id] = i;
  }
  for (int i = 1; i <= n; i++) {
    modify(1, 1, n + m, p[i], 1);
  }
  printf("%lld\n", t[1].ans);
  for (int i = 1; i <= m; i++) {
    modify(1, 1, n + m, p[q[i]], 0);
    modify(1, 1, n + m, p[n + i], 1);
    p[q[i]] = p[n + i];
    printf("%lld\n", t[1].ans);
  }
  return 0;
}
