#include <bits/stdc++.h>
using namespace std;
int n, q, cnt, a[300100], qx[300100], qy[300100], p[300100], m[300100],
    mi[300100], lsh[300100 * 2], v[300100 * 8], s1[300100 * 8], s2[300100 * 8],
    sz[300100 * 8];
int mo(int x, int y) { return x + y < 1000000007 ? x + y : x + y - 1000000007; }
int mul(int x, int y) { return 1ll * x * y % 1000000007; }
map<int, int> mp;
void updata(int x, int ls, int rs) {
  sz[x] = sz[ls] + sz[rs];
  v[x] = mo(mo(v[ls], v[rs]), mul(mi[sz[ls]], mul(s1[ls], s2[rs])));
  s1[x] = mo(s1[ls], mul(s1[rs], m[sz[ls]]));
  s2[x] = mo(s2[ls], mul(s2[rs], mi[sz[ls]]));
}
int get(int x, int k, int ret = 0) {
  for (int i = 1; i <= k; i++)
    for (int j = i + 1; j <= k; j++)
      ret = mo(ret, mul(mul(x, x), mi[j - i + 1]));
  return ret;
}
void add(int x, int l, int r, int p, int w, int y) {
  if (l == r) {
    sz[x] += y;
    s1[x] += y * w;
    s2[x] += y * mul(w, 500000004);
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    add(x << 1, l, mid, p, w, y);
  else
    add(x << 1 | 1, mid + 1, r, p, w, y);
  updata(x, x << 1, x << 1 | 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), lsh[++cnt] = a[i];
  m[0] = mi[0] = 1;
  for (int i = 1; i <= n + 1; i++) m[i] = m[i - 1] * 2 % 1000000007;
  for (int i = 1; i <= n + 1; i++)
    mi[i] = 1ll * mi[i - 1] * 500000004 % 1000000007;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++)
    scanf("%d%d", &qx[i], &qy[i]), lsh[++cnt] = qy[i];
  sort(lsh + 1, lsh + cnt + 1);
  for (int i = 1; i <= cnt; i++)
    if (lsh[i] != lsh[i - 1]) mp[lsh[i]] = i;
  for (int i = 1; i <= n; i++)
    add(1, 1, cnt, mp[a[i]], a[i], 1), p[i] = mp[a[i]], mp[a[i]]++;
  printf("%d\n", v[1]);
  for (int i = 1; i <= q; i++) {
    add(1, 1, cnt, p[qx[i]], a[qx[i]], -1);
    add(1, 1, cnt, mp[qy[i]], qy[i], 1);
    p[qx[i]] = mp[qy[i]];
    mp[qy[i]]++;
    a[qx[i]] = qy[i];
    printf("%d\n", v[1]);
  }
}
