#include <bits/stdc++.h>
using namespace std;
long long n, k, q, i, pa[300005], inv[300005], indx, chng;
struct node {
  long long ans, sz, up, 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++;
        up += inv[sz] * x;
        dw += inv[sz] * x;
        ans += ((inv[1] - inv[sz]) * x % 1000000007 * x) % 1000000007;
      } else {
        if (d == -1) {
          ans -= ((inv[1] - inv[sz]) * x % 1000000007 * x);
          dw -= inv[sz] * x;
          up -= inv[sz] * x;
          sz--;
        }
      }
      up %= 1000000007;
      dw %= 1000000007;
      ans %= 1000000007;
      ans = (ans + 1000000007) % 1000000007;
      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 %= 1000000007;
    dw %= 1000000007;
    ans %= 1000000007;
    ans = (ans + 1000000007) % 1000000007;
    if (le->sz == 0) {
      delete (le);
      le = NULL;
    }
    if (ri->sz == 0) {
      delete (ri);
      ri = NULL;
    }
  }
} *lol = new node();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  inv[0] = 1;
  inv[1] = 500000004;
  cin >> n;
  for (i = 2; i <= n; i++) {
    if (inv[i - 1] % 2 == 0) {
      inv[i] = inv[i - 1] / 2;
    } else {
      inv[i] = (inv[i - 1] + 1000000007) / 2;
    }
  }
  for (i = 0; i < n; i++) {
    cin >> pa[i];
    lol->update(1, 1000000000, pa[i], 1);
  }
  cin >> q;
  for (i = 0; i < q; i++) {
    cout << lol->ans << '\n';
    int la, lb;
    cin >> la >> lb;
    lol->update(1, 1000000000, pa[la - 1], -1);
    lol->update(1, 1000000000, lb, 1);
    pa[la - 1] = lb;
  }
  cout << lol->ans << "\n";
}
