#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
int a[N];
long long pw2[N], p2i = 500000004ll;
struct node {
  long long s1 = 0, s2 = 0, v, sm = 0;
  int sz = 0, i = -1;
  node() {}
  node(long long v, int i) : v(v), i(i) {
    sz = 1;
    s1 = s2 = v * p2i % mod;
  }
  bool operator<(const node& rhs) const {
    return v == rhs.v ? i < rhs.i : v < rhs.v;
  }
};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T>
struct treap {
  vector<int> L, R, prio;
  vector<T> val;
  int root = 0;
  treap() {
    L.emplace_back(), R.emplace_back(), prio.emplace_back(), val.emplace_back();
  }
  long long genRnd() {
    return uniform_int_distribution<long long>(0, 1e9)(rng);
  }
  int create(const T& v, long long p) {
    val.emplace_back(v), L.emplace_back(), R.emplace_back(),
        prio.emplace_back(p);
    return (int)(val).size() - 1;
  }
  void merge(int i, T& y, T& z) {
    T& x = val[i];
    x.sz = 1 + y.sz + z.sz;
    x.s1 = (z.s1 + (x.v + y.s1) * pw2[z.sz + 1]) % mod;
    x.s2 = (y.s2 + (x.v + z.s2) * pw2[y.sz + 1]) % mod;
    x.sm = (y.sm + z.sm + (x.v + y.s1) * z.s2 + y.s1 * x.v) % mod;
  }
  void split(int cur, int& l, int& r, const T& v) {
    if (!cur)
      l = r = 0;
    else if (val[cur] < v) {
      int x = R[l = cur];
      split(R[cur], x, r, v);
      R[l] = x;
      merge(l, val[L[l]], val[R[l]]);
    } else {
      int x = L[r = cur];
      split(L[cur], l, x, v);
      L[r] = x;
      merge(r, val[L[r]], val[R[r]]);
    }
  }
  void merge(int& cur, int l, int r) {
    if (!l || !r) {
      cur = !l ? r : l;
      return;
    } else if (prio[l] > prio[r]) {
      int x = R[cur = l];
      merge(x, R[l], r);
      R[cur] = x;
    } else {
      int x = L[cur = r];
      merge(x, l, L[r]);
      L[cur] = x;
    }
    merge(cur, val[L[cur]], val[R[cur]]);
  }
  void add(int& cur, const T& v, long long p) {
    if (!cur) {
      cur = create(v, p);
      return;
    }
    if (p > prio[cur]) {
      int nx = create(v, p);
      split(cur, L[nx], R[nx], v);
      cur = nx;
    } else {
      if (val[cur] < v) {
        int x = R[cur];
        add(x, v, p);
        R[cur] = x;
      } else {
        int x = L[cur];
        add(x, v, p);
        L[cur] = x;
      }
    }
    merge(cur, val[L[cur]], val[R[cur]]);
  }
  void rem(int& cur, const T& v) {
    if (!(v < val[cur]) && !(val[cur] < v)) {
      merge(cur, L[cur], R[cur]);
    } else if (val[cur] < v) {
      int x = R[cur];
      rem(x, v);
      R[cur] = x;
    } else {
      int x = L[cur];
      rem(x, v);
      L[cur] = x;
    }
    if (cur != 0) merge(cur, val[L[cur]], val[R[cur]]);
  }
  long long ins(long long v, int i) {
    T tmp(v, i);
    add(root, tmp, genRnd());
    return val[root].sm;
  }
  void del(long long v, int i) {
    T tmp(v, i);
    rem(root, tmp);
  }
};
int main() {
  treap<node> t = treap<node>();
  int n;
  scanf("%d", &n);
  pw2[0] = 1;
  for (int i = 1; i <= n; i++) pw2[i] = p2i * pw2[i - 1] % mod;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    ans = t.ins(a[i], i);
  }
  printf("%I64d\n", ans * p2i % mod);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int j, x;
    scanf("%d %d", &j, &x);
    t.del(a[j], j);
    a[j] = x;
    ans = t.ins(a[j], j);
    printf("%I64d\n", ans * p2i % mod);
  }
  return 0;
}
