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;
template <typename A, typename B, typename C>
struct triple {
  A X;
  B Y;
  C Z;
  triple(A a = 0, B b = 0, C c = 0) : X(a), Y(b), Z(c) {}
};
template <typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0) {
  return triple<A, B, C>(a, b, c);
}
template <typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b) {
  if (a.X != b.X) return a.X < b.X;
  if (a.Y != b.Y) return a.Y < b.Y;
  return a.Z < b.Z;
}
template <typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p) {
  ofs << "( " << p.first << " , " << p.second << " )";
  return ofs;
}
template <typename T>
void print(T a) {
  for (auto i : a) cout << i << ' ';
  cout << '\n';
}
template <typename T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
template <typename T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
const long long mod = 1e9 + 7;
long long d2;
vector<long long> some;
struct node {
  long long ans, sum_pw, sum_p, pw, p;
  node() {}
  node(long long x) {
    p = d2;
    pw = 2;
    sum_p = sum_pw = some[x];
    ans = 0;
  }
};
node mrg(const node& a, const node& b) {
  if (a.sum_p < 0) return b;
  if (b.sum_p < 0) return a;
  node res;
  res.p = (a.p * b.p) % mod;
  res.pw = (a.pw * b.pw) % mod;
  res.sum_p = (a.sum_p + b.sum_p * a.p) % mod;
  res.sum_pw = (a.sum_pw + b.sum_pw * a.pw) % mod;
  long long ans = (a.sum_pw * b.sum_p) % mod;
  (ans *= a.p) %= mod;
  (ans *= d2) %= mod;
  res.ans = (a.ans + b.ans + ans) % mod;
  return res;
}
vector<node> tree;
void bld(long long v, long long l, long long r) {
  if (l > r) return;
  if (l == r) {
    tree[v] = node(l);
    return;
  }
  long long m = l + r >> 1;
  bld(v << 1, l, m);
  bld(v << 1 | 1, m + 1, r);
  tree[v] = mrg(tree[v << 1], tree[v << 1 | 1]);
}
void ch(long long v, long long l, long long r, long long pos, long long nv) {
  if (l > r) return;
  if (l == r) {
    some[l] = nv;
    tree[v] = node(l);
    return;
  }
  long long m = l + r >> 1;
  if (pos <= m)
    ch(v << 1, l, m, pos, nv);
  else
    ch(v << 1 | 1, m + 1, r, pos, nv);
  tree[v] = mrg(tree[v << 1], tree[v << 1 | 1]);
}
long long pw(long long x) {
  if (!x) return 1;
  if (x & 1) return 2 * pw(x - 1) % mod;
  long long h = pw(x >> 1);
  return h * h % mod;
}
const long long mxn = 600606;
vector<long long> pos(mxn), cur(mxn);
signed main() {
  srand(time(NULL));
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  d2 = pw(mod - 2);
  long long n;
  cin >> n;
  vector<long long> rr(n);
  vector<pair<long long, long long> > a(n);
  for (long long i = 0; i < (n); i++) {
    cin >> a[i].first;
    a[i].second = i;
    rr[i] = a[i].first;
  }
  long long q;
  cin >> q;
  vector<pair<long long, long long> > ask(q);
  for (long long i = 0; i < (q); i++) {
    cin >> ask[i].first >> ask[i].second;
    ask[i].first--;
    a.push_back(make_pair(ask[i].second, i + n));
  }
  sort(a.begin(), a.end());
  some.resize(n + q);
  for (long long i = 0; i < ((long long)(a.size())); i++)
    pos[a[i].second] = i, cur[i] = i;
  some.assign(mxn, -1);
  for (long long i = 0; i < (n); i++) some[pos[i]] = rr[i];
  tree.resize(4 * mxn);
  bld(1, 0, n + q - 1);
  cout << tree[1].ans << '\n';
  for (long long i = 0; i < (q); i++) {
    long long x = ask[i].first, nv = ask[i].second;
    ch(1, 0, n + q - 1, pos[cur[x]], -1);
    cur[x] = i + n;
    ch(1, 0, n + q - 1, pos[cur[x]], nv);
    cout << tree[1].ans << '\n';
  }
}