#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int mxn = 600000;
int n, q;
long long a[mxn], b[mxn], d[mxn], first[mxn], p[mxn], it[mxn];
struct segTree {
  int l, r;
  segTree *tl, *tr;
  long long vl, lv, rv, second;
  segTree(int l, int r) : l(l), r(r) {
    vl = lv = rv = second = 0;
    if (l != r) {
      int mid = (l + r) / 2;
      tl = new segTree(l, mid);
      tr = new segTree(mid + 1, r);
      pul();
    } else {
      upd(it[l] < n);
    }
  }
  void upd(int x) {
    (lv += mod + x * a[it[l]] * p[1] % mod) %= mod;
    (rv += mod + x * a[it[l]] * p[1] % mod) %= mod;
    second += x;
  }
  void pul() {
    vl = (tl->vl + tr->vl + tl->lv * tr->rv) % mod;
    lv = (p[tr->second] * tl->lv + tr->lv) % mod;
    rv = (tl->rv + p[tl->second] * tr->rv) % mod;
    second = tl->second + tr->second;
  }
  void add(int x, int v) {
    if (x < l || r < x) return;
    if (l == r) return upd(v);
    tl->add(x, v), tr->add(x, v);
    pul();
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  p[0] = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = d[i] = it[i] = i;
    p[i + 1] = (mod + 1) / 2 * p[i] % mod;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x;
    cin >> x >> a[n + i];
    x--;
    b[n + i] = d[x], d[x] = it[n + i] = n + i;
  }
  sort(it, it + n + q, [&](int x, int y) { return a[x] < a[y]; });
  for (int i = 0; i < n + q; i++) first[it[i]] = i;
  segTree tre(0, n + q - 1);
  cout << tre.vl << '\n';
  for (int i = 0; i < q; i++) {
    tre.add(first[b[n + i]], -1);
    tre.add(first[n + i], 1);
    cout << tre.vl << '\n';
  }
  return 0;
}
