#include <bits/stdc++.h>
using namespace std;
const int N = 600000 + 600;
const long long MOD = 1000000007LL;
long long pow2[N];
long long invpow2[N];
long long add(long long a, long long b) { return (a + b) % MOD; }
long long mul(long long a, long long b) { return (a * b) % MOD; }
struct Node {
  Node() {}
  Node(long long val_, long long prefix_, long long suffix_, int count_)
      : val(val_), prefix(prefix_), suffix(suffix_), count(count_) {}
  long long val;
  long long prefix;
  long long suffix;
  int count;
} node[N << 2];
void push_up(int p, int l, int r) {
  int lson = p << 1;
  int rson = lson | 1;
  node[p].count = node[lson].count + node[rson].count;
  node[p].prefix =
      add(node[lson].prefix, mul(node[rson].prefix, pow2[node[lson].count]));
  node[p].suffix =
      add(node[rson].suffix, mul(node[lson].suffix, pow2[node[rson].count]));
  long long t = mul(node[lson].val, pow2[node[rson].count]);
  node[p].val = 0;
  node[p].val = add(node[p].val, t);
  t = mul(node[rson].val, pow2[node[lson].count]);
  node[p].val = add(node[p].val, t);
  t = mul(node[lson].prefix, node[rson].suffix);
  node[p].val = add(node[p].val, t);
}
void update(int p, int l, int r, int x, const Node &y) {
  if (l == r) {
    node[p] = y;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    update(p << 1, l, mid, x, y);
  else
    update(p << 1 | 1, mid + 1, r, x, y);
  push_up(p, l, r);
}
void solve() {
  int n;
  cin >> n;
  vector<pair<int, int> > vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i].first;
    vec[i].second = i;
  }
  int q;
  cin >> q;
  vector<int> del(q);
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    del[i] = x - 1;
    vec.push_back({y, n + i});
  }
  sort(vec.begin(), vec.end());
  vector<int> pos(vec.size());
  for (int i = 0; i < vec.size(); i++) {
    pos[vec[i].second] = i;
  }
  int m = vec.size() - 1;
  for (int i = 0; i < n; i++) {
    int x = pos[i];
    int y = vec[x].first;
    update(1, 0, m, x, Node{0, y, y, 1});
  }
  cout << mul(node[1].val, invpow2[n]) << endl;
  for (int i = 0; i < q; i++) {
    int x = pos[del[i]];
    update(1, 0, m, x, Node{0, 0, 0, 0});
    x = pos[n + i];
    int y = vec[x].first;
    pos[del[i]] = x;
    update(1, 0, m, x, Node{0, y, y, 1});
    cout << mul(node[1].val, invpow2[n]) << endl;
  }
}
int main() {
  pow2[0] = 1;
  for (int i = 1; i < N; i++) {
    pow2[i] = mul(pow2[i - 1], 2);
  }
  invpow2[0] = 1;
  for (int i = 1; i < N; i++) {
    invpow2[i] = mul(invpow2[i - 1], 500000004);
  }
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
