#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9 + 5;
const int MOD = 1e9 + 7;
const long long ooll = 1e18;
const int N = 6e5 + 5;
int pw[N];
long long powermod(long long a, long long b) {
  if (b == 0) return 1;
  long long res = powermod(a, b / 2);
  res = (res * res) % MOD;
  if (b & 1) res = (res * a) % MOD;
  return res;
}
void pre() {
  int i;
  pw[0] = 1;
  for (i = 1; i < N; i++) {
    pw[i] = (pw[i - 1] << 1);
    if (pw[i] >= MOD) pw[i] -= MOD;
  }
}
struct Node {
  int pref, suf, sum, cnt;
  Node() : pref(0), suf(0), sum(0), cnt(0) {}
  Node(int p, int s, int ss, int c) : pref(p), suf(s), sum(ss), cnt(c) {}
} Tree[4 * N];
Node Merge(Node a, Node b) {
  Node res;
  res.cnt = a.cnt + b.cnt;
  res.pref = (a.pref + b.pref * 1LL * pw[a.cnt]) % MOD;
  res.suf = (a.suf * 1LL * pw[b.cnt] + b.suf) % MOD;
  res.sum = (a.sum * 1LL * pw[b.cnt] + b.sum * 1LL * pw[a.cnt] +
             a.pref * 1LL * b.suf) %
            MOD;
  return res;
}
int v[N], f[N], w[N];
void build(int node, int st, int en) {
  if (st == en) {
    int now = (v[st] * 1LL * (pw[f[st]] - 1)) % MOD;
    int sum = (v[st] * 1LL * v[st]) % MOD;
    int mul = 0;
    if (f[st] > 1) {
      mul = (pw[f[st] - 1] * 1LL * (f[st] - 2) + 1) % MOD;
    }
    sum = (sum * 1LL * mul) % MOD;
    Tree[node] = Node(now, now, sum, f[st]);
    return;
  }
  int m = (st + en) >> 1;
  build(2 * node + 1, st, m);
  build(2 * node + 2, m + 1, en);
  Tree[node] = Merge(Tree[2 * node + 1], Tree[2 * node + 2]);
}
void upd(int pos, int node, int st, int en) {
  if (st == en) {
    int now = (v[st] * 1LL * (pw[f[st]] - 1)) % MOD;
    int sum = (v[st] * 1LL * v[st]) % MOD;
    int mul = 0;
    if (f[st] > 1) {
      mul = (pw[f[st] - 1] * 1LL * (f[st] - 2) + 1) % MOD;
    }
    sum = (sum * 1LL * mul) % MOD;
    Tree[node] = Node(now, now, sum, f[st]);
    return;
  }
  int m = (st + en) >> 1;
  if (pos <= m)
    upd(pos, 2 * node + 1, st, m);
  else
    upd(pos, 2 * node + 2, m + 1, en);
  Tree[node] = Merge(Tree[2 * node + 1], Tree[2 * node + 2]);
}
void disp(int node, int st, int en) {
  cout << "(" << st << "," << en << ") - > ";
  cout << Tree[node].pref << " " << Tree[node].suf << " " << Tree[node].sum
       << " " << Tree[node].cnt << '\n';
  if (st == en) return;
  int m = (st + en) >> 1;
  disp(2 * node + 1, st, m);
  disp(2 * node + 2, m + 1, en);
}
void solve() {
  int n, i;
  cin >> n;
  vector<int> dist;
  map<int, int> mp;
  for (i = 0; i < n; i++) {
    cin >> w[i];
    dist.push_back(w[i]);
  }
  int q;
  cin >> q;
  vector<array<int, 2> > qu(q);
  for (i = 0; i < q; i++) {
    cin >> qu[i][0] >> qu[i][1];
    dist.push_back(qu[i][1]);
  }
  sort(dist.begin(), dist.end());
  dist.erase(unique(dist.begin(), dist.end()), dist.end());
  int m = dist.size();
  for (i = 0; i < m; i++) {
    mp[dist[i]] = i;
    f[i] = 0;
    v[i] = dist[i];
  }
  for (i = 0; i < n; i++) f[mp[w[i]]]++;
  build(0, 0, m - 1);
  int pinv = powermod(2, MOD - 1 - n);
  cout << (Tree[0].sum * 1LL * pinv) % MOD << '\n';
  for (i = 0; i < q; i++) {
    int pos = qu[i][0] - 1, x = qu[i][1];
    int upd_pos = mp[w[pos]];
    f[upd_pos]--;
    upd(upd_pos, 0, 0, m - 1);
    w[pos] = x;
    upd_pos = mp[x];
    f[upd_pos]++;
    upd(upd_pos, 0, 0, m - 1);
    cout << (Tree[0].sum * 1LL * pinv) % MOD << '\n';
  }
}
int main() {
  pre();
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  for (int tc = 1; tc <= t; ++tc) {
    solve();
  }
  return 0;
}
