#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
int stot, stop, sstk[MAXN], n, root1, root2, root3, root, l1, r1, m, pos, x;
const long long mod = 1e9 + 7;
const long long inv2 = 500000004;
int id[MAXN];
long long pw2[MAXN];
struct arrnode {
  long long val;
  int id;
} arr[MAXN];
bool cmp(const arrnode &A, const arrnode &B) { return A.val < B.val; }
long long quickpow(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) {
      ans = (x * ans) % mod;
    }
    x = (x * x) % mod;
    y >>= 1;
  }
  return ans;
}
struct tree {
  int ch[2];
  int fa;
  long long size;
  long long num;
  long long pre, suf, sum, ans;
} t[MAXN];
tree operator+(const tree &a, const tree &b) {
  tree c;
  c.ans = (a.ans * pw2[b.size] % mod + b.suf * a.pre % mod +
           b.ans * pw2[a.size] % mod) %
          mod;
  c.pre = (a.pre + b.pre * pw2[a.size] % mod) % mod;
  c.size = a.size + b.size;
  c.suf = (b.suf + a.suf * pw2[b.size] % mod) % mod;
  return c;
}
void update(int root) {
  tree temp;
  temp.size = 1;
  temp.suf = t[root].num;
  temp.ans = 0;
  temp.pre = t[root].num;
  if (t[root].ch[0]) {
    temp = t[t[root].ch[0]] + temp;
  }
  if (t[root].ch[1]) {
    temp = temp + t[t[root].ch[1]];
  }
  t[root].ans = temp.ans;
  t[root].size = temp.size;
  t[root].pre = temp.pre;
  t[root].suf = temp.suf;
}
void rot(int root) {
  int fa = t[root].fa;
  int gfa = t[fa].fa;
  int t1 = (root != t[fa].ch[0]);
  int t2 = (fa != t[gfa].ch[0]);
  int ch = t[root].ch[1 ^ t1];
  t[root].fa = gfa;
  t[root].ch[1 ^ t1] = fa;
  t[fa].ch[0 ^ t1] = ch;
  t[fa].fa = root;
  t[ch].fa = fa;
  t[gfa].ch[0 ^ t2] = root;
  update(fa);
  return;
}
int splay(int root) {
  while (t[root].fa) {
    int fa = t[root].fa, gfa = t[fa].fa;
    if (gfa) {
      (t[fa].ch[0] == root) ^ (t[gfa].ch[0] == fa) ? rot(root) : rot(fa);
    }
    rot(root);
  }
  update(root);
  return root;
}
int kth(int root, int k) {
  for (;;) {
    if (k <= t[t[root].ch[0]].size) {
      root = t[root].ch[0];
    } else if (k > t[t[root].ch[0]].size + 1) {
      k -= t[t[root].ch[0]].size + 1;
      root = t[root].ch[1];
    } else {
      return splay(root);
    }
  }
}
int findnum(int root, int num) {
  while (root && t[root].num != num && t[root].ch[num > t[root].num])
    root = t[root].ch[num > t[root].num];
  return splay(root);
}
int findpre(int root) {
  root = t[root].ch[0];
  while (t[root].ch[1]) root = t[root].ch[1];
  return splay(root);
}
int findnex(int root) {
  root = t[root].ch[1];
  while (t[root].ch[0]) root = t[root].ch[0];
  return splay(root);
}
int links(int root1, int root2) {
  if (!root1 || !root2) return root1 | root2;
  root1 = kth(root1, t[root1].size);
  t[root1].ch[1] = root2;
  t[root2].fa = root1;
  update(root1);
  return root1;
}
void cuts(int root, int k, int &root1, int &root2) {
  if (k == 0) {
    root1 = 0;
    root2 = root;
    return;
  }
  root1 = kth(root, k);
  root2 = t[root1].ch[1];
  t[root1].ch[1] = t[root2].fa = 0;
  update(root1);
  return;
}
int build(int l, int r) {
  if (r < l) return 0;
  int mid = (l + r) >> 1;
  int new_node = ++stot;
  t[new_node].size = 1;
  t[new_node].num = arr[mid].val;
  id[arr[mid].id] = new_node;
  t[new_node].fa = 0;
  t[new_node].ch[0] = build(l, mid - 1);
  t[new_node].ch[1] = build(mid + 1, r);
  t[t[new_node].ch[0]].fa = new_node;
  t[t[new_node].ch[1]].fa = new_node;
  update(new_node);
  return new_node;
}
void dfs(int root) {
  if (t[root].ch[0]) {
    dfs(t[root].ch[0]);
  }
  cout << "root " << root << ":" << t[root].num << " " << t[root].size << endl;
  if (t[root].ch[1]) {
    dfs(t[root].ch[1]);
  }
  return;
}
int main() {
  pw2[0] = 1;
  for (int i = 1; i <= 300000; ++i) {
    pw2[i] = pw2[i - 1] * 2 % mod;
  }
  scanf("%d", &n);
  if (n == 1) {
    scanf("%*d");
    scanf("%d", &m);
    for (int i = 0; i <= m; ++i) {
      printf("0\n");
    }
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &arr[i].val);
    arr[i].id = i;
  }
  sort(arr + 1, arr + 1 + n, cmp);
  root = build(1, n);
  printf("%lld\n", t[root].ans * quickpow(inv2, n) % mod);
  scanf("%d", &m);
  while (m--) {
    scanf("%d %d", &pos, &x);
    root = splay(id[pos]);
    root1 = t[root].ch[0];
    t[root1].fa = t[root].ch[0] = 0;
    root2 = t[root].ch[1];
    t[root2].fa = t[root].ch[1] = 0;
    root3 = root;
    t[root3].num = x;
    update(root3);
    root = links(root1, root2);
    root = findnum(root, x);
    if (t[root].num > x) {
      if (t[root].ch[0] == 0) {
        root = links(root3, root);
      } else {
        root = findpre(root);
        root2 = t[root].ch[1];
        t[root2].fa = t[root].ch[1] = 0;
        update(root);
        root = links(root, root3);
        root = links(root, root2);
      }
    } else {
      if (t[root].ch[1] == 0) {
        root = links(root, root3);
      } else {
        root = findnex(root);
        root2 = t[root].ch[0];
        t[root2].fa = t[root].ch[0] = 0;
        update(root);
        root1 = root;
        root = links(root2, root3);
        root = links(root, root1);
      }
    }
    printf("%lld\n", t[root].ans * quickpow(inv2, n) % mod);
  }
  return 0;
}
