#include <bits/stdc++.h>
using namespace std;
int n;
long long MOD = 1000000007;
long long inv[999999];
long long a[900005];
struct node {
  long long ans;
  long long sz;
  long long up;
  long long dw;
  node *le, *ri;
  void update(int l, int r, int x, int d) {
    if (l > x || r < x) return;
    if (l == r) {
      if (d == 1) {
        sz += 1;
        up += inv[sz] * x;
        dw += inv[sz] * x;
        ans += (inv[1] - inv[sz]) * x % MOD * x;
      } else if (d == -1) {
        ans -= (inv[1] - inv[sz]) * x % MOD * x;
        up -= inv[sz] * x;
        dw -= inv[sz] * x;
        sz -= 1;
      }
      up %= MOD;
      dw %= MOD;
      ans %= MOD;
      ans = (ans + MOD) % MOD;
      return;
    }
    if (le == NULL) le = new node();
    if (ri == NULL) ri = new node();
    int m = (l + r) / 2;
    le->update(l, m, x, d);
    ri->update(m + 1, r, x, d);
    sz = le->sz + ri->sz;
    up = le->up + inv[le->sz] * ri->up;
    dw = ri->dw + inv[ri->sz] * le->dw;
    ans = ri->up * le->dw + le->ans + ri->ans;
    up %= MOD;
    dw %= MOD;
    ans %= MOD;
    ans = (ans + MOD) % MOD;
    if (le->sz == 0) {
      delete (le);
      le = NULL;
    }
    if (ri->sz == 0) {
      delete (ri);
      ri = NULL;
    }
  }
} *seg = new node();
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int Q, n;
  cin >> n;
  inv[0] = 1;
  inv[1] = 500000004;
  for (int i = 2; i <= n; i++) inv[i] = inv[i - 1] * inv[1] % MOD;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) seg->update(1, 1000000000, a[i], 1);
  cout << seg->ans << '\n';
  cin >> Q;
  while (Q--) {
    int l, r;
    cin >> l >> r;
    seg->update(1, 1000000000, a[l], -1);
    a[l] = r;
    seg->update(1, 1000000000, a[l], 1);
    cout << seg->ans << '\n';
  }
  return 0;
}
