#include <bits/stdc++.h>
using namespace std;
long long const mod = 1e9 + 7;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  os << "(" << a.first << ", " << a.second << ")";
  return os;
}
array<long long, 600010> b, rb;
struct LazySegmentTree {
 private:
  int n;
  vector<long long> node, lazy;

 public:
  LazySegmentTree(vector<long long> v) {
    int sz = v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    lazy.resize(2 * n - 1, 0);
    for (int i = 0; i < sz; ++i) node[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; --i) {
      node[i] = node[i * 2 + 1] + node[i * 2 + 2];
      if (node[i] > mod) node[i] -= mod;
    }
  }
  void eval(int k, int l, int r) {
    if (lazy[k] != 0) {
      if (lazy[k] > 0)
        (node[k] *= b[lazy[k]]) %= mod;
      else
        (node[k] *= rb[-lazy[k]]) %= mod;
      if (r - l > 1) {
        lazy[2 * k + 1] += lazy[k];
        lazy[2 * k + 2] += lazy[k];
      }
      lazy[k] = 0;
    }
  }
  void mul2(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] += x;
      eval(k, l, r);
    } else {
      mul2(a, b, x, 2 * k + 1, l, (l + r) / 2);
      mul2(a, b, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = node[2 * k + 1] + node[2 * k + 2];
      if (node[k] > mod) node[k] -= mod;
    }
  }
  void update(int a, long long x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (a + 1 <= l || r <= a) return;
    if (a <= l && r <= a + 1) {
      node[k] = x;
    } else {
      update(a, x, 2 * k + 1, l, (l + r) / 2);
      update(a, x, 2 * k + 2, (l + r) / 2, r);
      node[k] = node[2 * k + 1] + node[2 * k + 2];
      if (node[k] > mod) node[k] -= mod;
    }
  }
  long long getsum(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (b <= l || r <= a) return 0;
    eval(k, l, r);
    if (a <= l && r <= b) return node[k];
    long long vl = getsum(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = getsum(a, b, 2 * k + 2, (l + r) / 2, r);
    return (vl + vr > mod ? vl + vr - mod : vl + vr);
  }
};
struct BinaryIndexedTree {
 private:
  int n, b;
  vector<int> bit;

 public:
  BinaryIndexedTree(int n_) {
    n = n_ + 10;
    b = 1;
    while (b < n) b <<= 1;
    b >>= 1;
    bit = vector<int>(n, 0);
  }
  void add(int a, int w) {
    a++;
    for (int x = a; x < n; x += x & -x) bit[x] += w;
  }
  int sum(int a) {
    a++;
    int ret = 0;
    for (int x = a; x > 0; x -= x & -x) ret += bit[x];
    return ret;
  }
  void update(int a, int w) {
    int v = w - sum(a) + sum(a - 1);
    add(a, v);
  }
  int lower_bound(int w) {
    if (w <= 0) return 0;
    int x = 0;
    for (int k = b; k > 0; k /= 2) {
      if (x + k < n && bit[x + k] < w) {
        w -= bit[x + k];
        x += k;
      }
    }
    return x;
  }
};
int main() {
  int n, m, q;
  cin >> n;
  vector<long long> a(n);
  map<int, int> mp;
  for (int i = 0; i < n; ++i) scanf("%lld", &a[i]);
  for (int i = 0; i < n; ++i) mp[a[i]]++;
  cin >> q;
  vector<pair<int, long long>> c(q);
  for (int i = 0; i < q; ++i)
    scanf("%d%lld", &c[i].first, &c[i].second), c[i].first--;
  for (int i = 0; i < q; ++i) mp[c[i].second]++;
  vector<int> idx1(n), idx2(q);
  {
    int i = 0;
    for (auto& p : mp) {
      i += p.second;
      p.second = i - p.second;
    }
  }
  for (int i = 0; i < n; ++i) idx1[i] = mp[a[i]]++;
  for (int i = 0; i < q; ++i) idx2[i] = mp[c[i].second]++;
  m = n + q;
  vector<long long> l(m), r(m);
  BinaryIndexedTree bit(m);
  b[0] = 1;
  for (int i = 1; i < m; ++i) {
    b[i] = b[i - 1] * 2;
    if (b[i] > mod) b[i] -= mod;
  }
  rb[0] = 1;
  for (int i = 1; i < m; ++i) {
    if (rb[i - 1] & 1)
      rb[i] = (rb[i - 1] + mod) / 2;
    else
      rb[i] = rb[i - 1] / 2;
  }
  for (int i = 0; i < n; ++i) bit.add(idx1[i], 1);
  for (int i = 0; i < n; ++i) {
    int s = idx1[i];
    l[s] = a[i] * b[bit.sum(s) - 1] % mod;
    r[s] = a[i] * rb[bit.sum(s) - 1] % mod;
  }
  LazySegmentTree vl(l), vr(r);
  long long ans = 0;
  for (int i = 0; i < n; ++i)
    (ans += r[idx1[i]] * vl.getsum(0, idx1[i]) % mod * rb[1] % mod) %= mod;
  cout << ans << "\n";
  for (int i = 0; i < q; ++i) {
    int s = idx1[c[i].first], e = idx2[i];
    (ans -= vr.getsum(s, s + 1) * vl.getsum(0, s) % mod * rb[1] % mod) %= mod;
    (ans -= vl.getsum(s, s + 1) * vr.getsum(s + 1, m) % mod * rb[1] % mod) %=
        mod;
    (ans += vl.getsum(0, s) * vr.getsum(s + 1, m) % mod * rb[1] % mod) %= mod;
    vl.mul2(s, m, -1);
    vr.mul2(s, m, 1);
    vl.update(s, 0);
    vr.update(s, 0);
    bit.add(s, -1);
    idx1[c[i].first] = e;
    vl.mul2(e, m, 1);
    vr.mul2(e, m, -1);
    vl.update(e, c[i].second * b[bit.sum(e)] % mod);
    vr.update(e, c[i].second * rb[bit.sum(e)] % mod);
    bit.add(e, 1);
    (ans -= vl.getsum(0, e) * vr.getsum(e + 1, m) % mod * rb[1] % mod) %= mod;
    (ans += vr.getsum(e, e + 1) * vl.getsum(0, e) % mod * rb[1] % mod) %= mod;
    (ans += vl.getsum(e, e + 1) * vr.getsum(e + 1, m) % mod * rb[1] % mod) %=
        mod;
    cout << (ans + mod) % mod << "\n";
  }
}
