Problem: There are n officers in the Army of Byteland. Each officer has some power associated with him. The power of the i-th officer is denoted by p_{i}. As the war is fast approaching, the General would like to know the strength of the army.

The strength of an army is calculated in a strange way in Byteland. The General selects a random subset of officers from these n officers and calls this subset a battalion.(All 2^n subsets of the n officers can be chosen equally likely, including empty subset and the subset of all officers).

The strength of a battalion is calculated in the following way:

Let the powers of the chosen officers be a_{1},a_{2},…,a_{k}, where a_1 ≤ a_2 ≤ ... ≤ a_k. The strength of this battalion is equal to a_1a_2 + a_2a_3 + ... + a_{k-1}a_k. (If the size of Battalion is ≤ 1, then the strength of this battalion is 0).

The strength of the army is equal to the expected value of the strength of the battalion.

As the war is really long, the powers of officers may change. Precisely, there will be q changes. Each one of the form i x indicating that p_{i} is changed to x.

You need to find the strength of the army initially and after each of these q updates.

Note that the changes are permanent.

The strength should be found by modulo 10^{9}+7. Formally, let M=10^{9}+7. It can be shown that the answer can be expressed as an irreducible fraction p/q, where p and q are integers and qnot≡ 0 mod M). Output the integer equal to p⋅ q^{-1} mod M. In other words, output such an integer x that 0 ≤ x < M and x ⋅ q ≡ p mod M).

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 3⋅10^{5}) — the number of officers in Byteland's Army.

The second line contains n integers p_{1},p_{2},…,p_{n} (1 ≤ p_{i} ≤ 10^{9}).

The third line contains a single integer q (1 ≤ q ≤ 3⋅10^{5}) — the number of updates.

Each of the next q lines contains two integers i and x (1 ≤ i ≤ n,  1 ≤ x ≤ 10^{9}), indicating that p_{i} is updated to x .

Output

In the first line output the initial strength of the army.

In i-th of the next q lines, output the strength of the army after i-th update.

Examples

Input


2
1 2
2
1 2
2 1


Output


500000004
1
500000004


Input


4
1 2 3 4
4
1 5
2 5
3 5
4 5


Output


625000011
13
62500020
375000027
62500027

Note

In first testcase, initially, there are four possible battalions 

  * {} Strength = 0 
  * {1} Strength = 0 
  * {2} Strength = 0 
  * {1,2} Strength = 2 

So strength of army is (0+0+0+2)/(4) = 1/2

After changing p_{1} to 2, strength of battallion {1,2} changes to 4, so strength of army becomes 1.

After changing p_{2} to 1, strength of battalion {1,2} again becomes 2, so strength of army becomes 1/2.

Solution (in CPP):

Solution:
#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";
  }
}