#include <bits/stdc++.h>
using namespace std;
constexpr long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-9;
const long double pi = acos(-1.0);
long long mod_pow(long long a, long long n, long long m) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}
string sdir = "RDLU";
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
long long t2[1 << 19];
long long invt2[1 << 19];
long long inv2;
void init(int n) {
  t2[0] = 1;
  invt2[0] = 1;
  inv2 = (1 + mod) / 2;
  for (int i = 0; i < n + 5; i++) {
    t2[i + 1] = t2[i] * 2 % mod;
    invt2[i + 1] = invt2[i] * inv2 % mod;
  }
}
struct SegT {
 private:
  int n;
  vector<long long> node, lazy;
  const long long init_c = 0;

 public:
  SegT(int sz) {
    n = 1;
    while (n < sz) n <<= 1;
    node.resize(2 * n - 1, init_c);
    lazy.resize(2 * n - 1, 1);
  }
  SegT(vector<long long> &v) {
    int sz = v.size();
    n = 1;
    while (n < sz) n <<= 1;
    node.resize(2 * n - 1, init_c);
    lazy.resize(2 * n - 1, 1);
    for (int i = 0; i < sz; i++) {
      node[i + n - 1] = v[i];
    }
    for (int i = n - 1 - 1; i >= 0; i--) {
      node[i] = f(node[2 * i + 1], node[2 * i + 2]);
    }
  }
  long long f(long long a, long long b) {
    long long res = a + b;
    if (res >= mod) res -= mod;
    return res;
  }
  void eval(int k, int l, int r) {
    if (lazy[k] == 1) return;
    node[k] = node[k] * lazy[k] % mod;
    if (r - l > 1) {
      lazy[2 * k + 1] = lazy[2 * k + 1] * lazy[k] % mod;
      lazy[2 * k + 2] = lazy[2 * k + 2] * lazy[k] % mod;
    }
    lazy[k] = 1;
  }
  void add(long long x, int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (r <= a || b <= l) return;
    if (a <= l && r <= b) {
      lazy[k] = lazy[k] * x % mod;
      eval(k, l, r);
    } else {
      add(x, a, b, k * 2 + 1, l, (l + r) / 2);
      add(x, a, b, k * 2 + 2, (l + r) / 2, r);
      node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
    }
  }
  long long query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (r <= a || b <= l) return init_c;
    if (a <= l && r <= b)
      return node[k];
    else {
      long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return f(vl, vr);
    }
  }
  void update(int c, long long x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (r <= c || c + 1 <= l) return;
    if (c <= l && r <= c + 1) {
      node[k] = x;
    } else {
      update(c, x, k * 2 + 1, l, (l + r) / 2);
      update(c, x, k * 2 + 2, (l + r) / 2, r);
      node[k] = f(node[2 * k + 1], node[2 * k + 2]);
    }
  }
};
struct BIT {
 private:
  vector<long long> node;
  int n;

 public:
  BIT(int n_) {
    n = n_;
    node.resize(n, 0);
  }
  void add(int a, long long w) {
    for (int i = a; i < n; i |= i + 1) node[i] += w;
  }
  long long sum(int a) {
    long long ret = 0;
    for (int i = a - 1; i >= 0; i = (i & (i + 1)) - 1) ret += node[i];
    return ret;
  }
  long long sum(int a, int b) { return sum(b) - sum(a); }
};
void solve() {
  int n;
  cin >> n;
  init(n);
  vector<pair<long long, long long> > vs;
  vector<long long> in(n);
  for (int i = 0; i < n; i++) {
    cin >> in[i];
    vs.push_back({in[i], i});
  }
  int q;
  cin >> q;
  vector<int> locs(q);
  vector<long long> vals(q);
  for (int i = 0; i < q; i++) {
    cin >> locs[i];
    locs[i]--;
    cin >> vals[i];
    vs.push_back({vals[i], i + n});
  }
  sort((vs).begin(), (vs).end());
  BIT memo(n + q);
  long long sum = 0;
  vector<long long> ori1(n + q, 0), ori2(n + q, 0);
  int tmp = 0;
  long long csum = 0;
  for (int i = 0; i < n + q; i++) {
    int id = vs[i].second;
    if (id < n) {
      long long ad = csum * invt2[tmp] % mod * inv2 % mod * in[id] % mod;
      sum += ad;
      if (sum > mod) sum -= mod;
      ori1[i] = t2[tmp] * in[id] % mod;
      ori2[i] = invt2[tmp] * in[id] % mod;
      memo.add(i, 1);
      tmp++;
      csum += ori1[i];
      if (csum >= mod) csum -= mod;
    }
  }
  SegT st1(ori1);
  SegT st2(ori2);
  vector<int> cur(n);
  vector<int> tloc(q);
  for (int i = 0; i < n + q; i++) {
    int id = vs[i].second;
    if (id < n) {
      cur[id] = i;
    } else {
      tloc[id - n] = i;
    }
  }
  cout << sum << endl;
  for (int i = 0; i < q; i++) {
    int loc = cur[locs[i]];
    long long val = in[locs[i]];
    {
      int cl = memo.sum(0, loc);
      long long lesum = st1.query(0, loc);
      long long risum = st2.query(loc + 1, n + q);
      sum += lesum * risum % mod * inv2 % mod;
      if (sum >= mod) sum -= mod;
      lesum = lesum * invt2[cl] % mod * inv2 % mod * val % mod;
      sum -= lesum;
      if (sum < 0) sum += mod;
      risum = risum * t2[cl] % mod * inv2 % mod * val % mod;
      sum -= risum;
      if (sum < 0) sum += mod;
      memo.add(loc, -1);
      st1.update(loc, 0);
      st1.add(inv2, loc + 1, n + q);
      st2.update(loc, 0);
      st2.add(2, loc + 1, n + q);
    }
    loc = tloc[i];
    val = vals[i];
    {
      int cl = memo.sum(0, loc);
      memo.add(loc, 1);
      st1.update(loc, val * t2[cl] % mod);
      st1.add(2, loc + 1, n + q);
      st2.update(loc, val * invt2[cl] % mod);
      st2.add(inv2, loc + 1, n + q);
      long long lesum = st1.query(0, loc);
      long long risum = st2.query(loc + 1, n + q);
      sum -= lesum * risum % mod * inv2 % mod;
      if (sum < 0) sum += mod;
      lesum = lesum * invt2[cl] % mod * inv2 % mod * val % mod;
      sum += lesum;
      if (sum >= mod) sum -= mod;
      risum = risum * t2[cl] % mod * inv2 % mod * val % mod;
      sum += risum;
      if (sum >= mod) sum -= mod;
    }
    in[locs[i]] = vals[i];
    cur[locs[i]] = loc;
    cout << sum << "\n";
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  char nyaa;
  cin >> nyaa;
  return 0;
}
