#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
const int N = 300005;
int RP() {
  int x = 0;
  for (int i = (int)(1); i <= (int)(9); i++) x = x * 10 + rand() % 10;
  return x;
}
struct node {
  int p, pl, pr, sum;
} t[N], v[N];
int ls[N], rs[N], rp[N];
int a[N], fa[N], n, rt, Q;
node operator+(node a, node b) {
  node ans;
  ans.p = 1ll * a.p * b.p % mo;
  ans.pl = (a.pl + 1ll * a.p * b.pl) % mo;
  ans.pr = (b.pr + 1ll * b.p * a.pr) % mo;
  ans.sum = (a.sum + b.sum + 1ll * a.pr * b.pl) % mo;
  return ans;
}
void pushup(int x) {
  v[x] = t[x];
  if (ls[x]) fa[ls[x]] = x, v[x] = v[ls[x]] + v[x];
  if (rs[x]) fa[rs[x]] = x, v[x] = v[x] + v[rs[x]];
}
void init(int x, int val) {
  t[x].p = (mo + 1) / 2;
  t[x].pl = 1ll * (mo + 1) / 2 * val % mo;
  t[x].pr = 1ll * (mo + 1) / 2 * val % mo;
  t[x].sum = 0;
  pushup(x);
}
pair<int, int> split(int k, pair<int, int> val) {
  if (!k) return pair<int, int>(0, 0);
  if (pair<int, int>(a[k], k) <= val) {
    pair<int, int> ans = split(rs[k], val);
    rs[k] = ans.first;
    ans.first = k;
    pushup(k);
    return ans;
  } else {
    pair<int, int> ans = split(ls[k], val);
    ls[k] = ans.second;
    ans.second = k;
    pushup(k);
    return ans;
  }
}
int merge(int x, int y) {
  if (!x || !y) return x + y;
  if (rp[x] < rp[y]) {
    rs[x] = merge(rs[x], y);
    pushup(x);
    return x;
  } else {
    ls[y] = merge(x, ls[y]);
    pushup(y);
    return y;
  }
}
void output(int k) {
  if (!k) return;
  printf("YYN! %d %d %d %d\n", k, ls[k], rs[k], fa[k]);
  output(ls[k]);
  output(rs[k]);
}
void Erase(int id) {
  int x = merge(ls[id], rs[id]);
  if (id == rt)
    rt = x;
  else {
    if (ls[fa[id]] == id)
      ls[fa[id]] = x;
    else
      rs[fa[id]] = x;
    for (x = fa[id];; x = fa[x]) {
      pushup(x);
      if (x == rt) break;
    }
  }
  ls[id] = rs[id] = fa[id] = 0;
}
void Insert(int id) {
  pair<int, int> tmp = split(rt, pair<int, int>(a[id], id - 1));
  rt = merge(merge(tmp.first, id), tmp.second);
}
int main() {
  srand(time(NULL));
  scanf("%d", &n);
  for (int i = (int)(1); i <= (int)(n); i++) scanf("%d", &a[i]);
  for (int i = (int)(1); i <= (int)(n); i++) {
    rp[i] = RP();
    init(i, a[i]);
    Insert(i);
  }
  printf("%d\n", v[rt].sum);
  scanf("%d", &Q);
  while (Q--) {
    int x;
    scanf("%d", &x);
    Erase(x);
    scanf("%d", &a[x]);
    init(x, a[x]);
    Insert(x);
    printf("%d\n", v[rt].sum);
  }
}
