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.
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.Locale;
import java.util.Random;
import java.util.StringTokenizer;

public class Solution4 implements Runnable {
	
	public static final int M = 1000000000 + 7;
	public static final int I2 = modinv(2);
	
	private static Random rnd = new Random(366239);
	
	private PrintStream out;
	private BufferedReader in;
	private StringTokenizer st;
	
	public void solve() throws IOException {
		long time0 = System.currentTimeMillis();
		
		int n = nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = nextInt();
		}
		int q = nextInt();
		int[] qi = new int[q];
		int[] qx = new int[q];
		for (int i = 0; i < q; i++) {
			qi[i] = nextInt() - 1;
			qx[i] = nextInt();
		}
		int[] answer = solve(n, p, q, qi, qx);
		out.println(answer[0]);
		for (int i = 0; i < q; i++) {
			out.println(answer[1 + i]);
		}
		
		
		System.err.println("time: " + (System.currentTimeMillis() - time0));
	}
	
	private int[] solve(int n, int[] p, int q, int[] qi, int[] qx) {
		MyNode root = null;
		int[] sum = new int[] {0};
		for (int i = 0; i < n; i++) {
			root = insert(root, i, p[i], sum);
		}
		int[] result = new int[1 + q];
		result[0] = sum[0];
		for (int qn = 0; qn < q; qn++) {
			root = remove(root, qi[qn], p[qi[qn]], sum);
			p[qi[qn]] = qx[qn];
			root = insert(root, qi[qn], p[qi[qn]], sum);
			result[1 + qn] = sum[0];
		}
		int div = 1;
		for (int i = 0; i < n; i++) {
			div = (int) ((1L * div * I2) % M);
		}
		for (int i = 0; i < result.length; i++) {
			result[i] = (int) ((1L * result[i] * div) % M);
		}
		return result;
	}
	
	private MyNode insert(MyNode root, int i, int p, int[] sum) {
		MyNodePair pair = split(root, i, p);
		sum[0] = (int) (((sum[0] - 1L * MyNode.getLeftSum(pair.left) * MyNode.getRightSum(pair.right)) % M + M) % M);
		sum[0] = (int) ((1L * sum[0] * 2) % M);
		sum[0] = (int) (((sum[0] + 1L * MyNode.getLeftSum(pair.left) * MyNode.getRightSum(pair.right)) % M + M) % M);
		
		sum[0] = (int) (((sum[0] + p * ((1L * MyNode.getLeftSum(pair.left) * MyNode.getPow(pair.right)) % M)) % M + M) % M);
		sum[0] = (int) (((sum[0] + p * ((1L * MyNode.getPow(pair.left) * MyNode.getRightSum(pair.right)) % M)) % M + M) % M);
		return join(pair.left, join(new MyNode(i, p), pair.right));
	}

	private MyNode remove(MyNode root, int i, int p, int[] sum) {
		MyNodePair pair = split(root, i, p);
		sum[0] = (int) (((sum[0] - p * ((1L * MyNode.getLeftSum(pair.left) * MyNode.getPow(pair.right)) % M)) % M + M) % M);
		sum[0] = (int) (((sum[0] - p * ((1L * MyNode.getPow(pair.left) * MyNode.getRightSum(pair.right)) % M)) % M + M) % M);
		
		sum[0] = (int) (((sum[0] - 1L * MyNode.getLeftSum(pair.left) * MyNode.getRightSum(pair.right)) % M + M) % M);
		sum[0] = (int) ((1L * sum[0] * I2) % M);
		sum[0] = (int) (((sum[0] + 1L * MyNode.getLeftSum(pair.left) * MyNode.getRightSum(pair.right)) % M + M) % M);
		return join(pair.left, pair.right);
	}

	private static MyNodePair split(MyNode node, int key_ind, int key_val) {
		if (node == null) {
			return new MyNodePair(null, null);
		}
		if (key_val < node.key_val || (key_val == node.key_val && key_ind < node.key_ind)) {
			MyNodePair result = split(node.left, key_ind, key_val);
			// Not persistent dirty hack
			node.left = result.right;
			node.recalc();
			result.right = node;
			return result;
		} else if (key_val > node.key_val || (key_val == node.key_val && key_ind > node.key_ind)) {
			MyNodePair result = split(node.right, key_ind, key_val);
			// Not persistent dirty hack
			node.right = result.left;
			node.recalc();
			result.left = node;
			return result;
		} else {
			return new MyNodePair(node.left, node.right);
		}
	}
		
	private static MyNode join(MyNode left, MyNode right) {
		if (left == null) {
			return right;
		}
		if (right == null) {
			return left;
		}
		if (left.heap < right.heap) {
			// Not persistent dirty hack
			left.right = join(left.right, right);
			left.recalc();
			return left;
		} else {
			// Not persistent dirty hack
			right.left = join(left, right.left);
			right.recalc();
			return right;
		}
	}

	public static class MyNodePair {
		public MyNode left;
		public MyNode right;
		public MyNodePair(MyNode left, MyNode right) {
			this.left = left;
			this.right = right;
		}
	}
	
	public static class MyNode {
		public int key_ind;
		public int key_val;
		public int heap;
		public MyNode left;
		public MyNode right;
		
		public int pow;
		public int leftSum;
		public int rightSum;
		
		public MyNode(int key_ind, int key_val) {
			this(key_ind, key_val, rnd.nextInt(), null, null);
		}
		
		public MyNode(int key_ind, int key_val, int heap, MyNode left, MyNode right) {
			this.key_ind = key_ind;
			this.key_val = key_val;
			this.heap = heap;
			this.left = left;
			this.right = right;
			recalc();
		}
		
		public void recalc() {
			pow = (int) ((2L * getPow(left) * getPow(right)) % M);
			long leftSum = (getLeftSum(left) + 1L * key_val * getPow(left)) % M;
			leftSum = (leftSum + getLeftSum(right) * 2L * getPow(left)) % M;
			this.leftSum = (int) leftSum;
			long rightSum = (getRightSum(right) + 1L * key_val * getPow(right)) % M;
			rightSum = (rightSum + getRightSum(left) * 2L * getPow(right)) % M;
			this.rightSum = (int) rightSum;
		}
		
		private static int getPow(MyNode node) {
			if (node == null) {
				return 1;
			} else {
				return node.pow;
			}
		}
		private static int getLeftSum(MyNode node) {
			if (node == null) {
				return 0;
			} else {
				return node.leftSum;
			}
		}
		private static int getRightSum(MyNode node) {
			if (node == null) {
				return 0;
			} else {
				return node.rightSum;
			}
		}
	}

	private static int modinv(long x) {
		BigInteger xb = BigInteger.valueOf(x);
		BigInteger mb = BigInteger.valueOf(M);
		BigInteger result = xb.modInverse(mb);
		return result.intValue();
	}
	
	public double nextDouble() throws IOException {
		return Double.parseDouble(next());
	}
	
	public long nextLong() throws IOException {
		return Long.parseLong(next());
	}
	
	public int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	
	public String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			st = new StringTokenizer(line);
		}
		return st.nextToken();
	}
	
	@Override
	public void run() {
		try {
			solve();
			out.close();
		} catch (Throwable e) {
			throw new RuntimeException(e);
		}
	}
	
	public Solution4(String name) throws IOException {
		Locale.setDefault(Locale.US);
		if (name == null) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintStream(new BufferedOutputStream(System.out));
		} else {
			in = new BufferedReader(new InputStreamReader(new FileInputStream(name + ".in")));
			out = new PrintStream(new BufferedOutputStream(new FileOutputStream(name + ".out")));
		}
		st = new StringTokenizer("");
	}
	
	public static void main(String[] args) throws IOException {
		new Thread(new Solution4(null)).start();
	}
}
