#include <bits/stdc++.h>
using namespace std;
const int lim = 600005;
const int lim2 = 300005;
const long long mod = 1000000007;
int tw[lim << 2];
long long t2[lim << 2][3];
long long pot[lim2];
int n, q, base = 1;
long long wart[lim][2];
int poz[lim2];
vector<pair<long long, int> > v;
int ret;
int lewy, prawy;
void merg(int x) {
  lewy = x << 1;
  prawy = lewy | 1;
  t2[x][0] = t2[lewy][0] + (t2[prawy][0] * pot[tw[lewy]]) % mod;
  if (t2[x][0] >= mod) t2[x][0] -= mod;
  t2[x][1] = (t2[lewy][0] * t2[prawy][2]) % mod;
  t2[x][1] += (t2[lewy][1] * pot[tw[prawy]]) % mod +
              (t2[prawy][1] * pot[tw[lewy]]) % mod;
  t2[x][1] %= mod;
  t2[x][2] = t2[prawy][2] + (t2[lewy][2] * pot[tw[prawy]]) % mod;
  if (t2[x][2] >= mod) t2[x][2] -= mod;
}
int kon, pocz;
void wypisz() {
  kon = (base << 1);
  pocz = 1;
  while (pocz < kon) {
    for (int i = pocz; i < (pocz << 1); i++)
      printf("|%d %lld %lld %lld|", tw[i], t2[i][0], t2[i][1], t2[i][2]);
    printf("\n");
    pocz <<= 1;
  }
}
void update(int x, long long val) {
  x += base;
  t2[x][0] = val;
  t2[x][2] = val;
  if (val)
    tw[x] = 1;
  else
    tw[x] = 0;
  x >>= 1;
  while (x) {
    tw[x] = tw[x << 1] + tw[(x << 1) | 1];
    merg(x);
    x >>= 1;
  }
}
void potenguj() {
  pot[0] = 1;
  for (int i = 1; i <= n; i++) {
    pot[i] = (pot[i - 1] << 1);
    if (pot[i] >= mod) pot[i] -= mod;
  }
}
long long odw, y3;
void gcd(int a, int b, long long& x, long long& y) {
  if (b) {
    long long x4, y4;
    gcd(b, a % b, x4, y4);
    x = y4;
    y = x4 - (a / b) * y4;
    return;
  }
  x = 1;
  y = 0;
}
void prep() {
  potenguj();
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) wart[v[i].second][1] = i;
  int temp = q + n;
  while (base < temp) base <<= 1;
  for (int i = 0; i < n; i++) update(wart[i][1], wart[i][0]);
  gcd(pot[n], mod, odw, y3);
  while (odw < 0) odw += mod;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> wart[i][0];
    v.push_back({wart[i][0], i});
  }
  cin >> q;
  for (int i = n; i < n + q; i++) {
    cin >> poz[i - n] >> wart[i][0];
    v.push_back({wart[i][0], i});
  }
  prep();
  cout << (t2[1][1] * odw) % mod << "\n";
  for (int i = 0; i < q; i++) {
    update(wart[poz[i] - 1][1], 0);
    wart[poz[i] - 1][1] = wart[n + i][1];
    update(wart[n + i][1], wart[n + i][0]);
    cout << (t2[1][1] * odw) % mod << "\n";
  }
  return 0;
}
