C. Counting Pops
time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Consider having two stacks of integers, one loaded with some distinct integers and the other empty. The following operation is performed until both stacks become empty:

  • Let $$$m$$$ be the minimum element among all integers in both the stacks.
  • If $$$m$$$ is at the top of its stack, pop it. Otherwise, pop the top element of $$$m$$$'s stack and push it into the other one.

For a sequence $$$S$$$ of distinct integers, define $$$f(S)$$$ as the number of operations performed if the first stack is loaded with $$$S$$$.

Given a permutation $$$p$$$ of length $$$n$$$, compute the sum of $$$f(S)$$$ over all non-empty subsequences $$$S$$$ of $$$p$$$.

Input

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases.

The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$).

The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$. It is guaranteed that $$$p$$$ is a permutation of $$$1$$$ to $$$n$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output

For each test case, print a single integer on a new line, the sum of $$$f(S)$$$ over all non-empty subsequences $$$S$$$ of $$$p$$$ modulo $$$10^9+7$$$.

Example
Input
5
3
2 3 1
4
2 4 1 3
5
4 1 3 5 2
2
1 2
7
3 5 4 7 1 6 2
Output
14
44
121
5
734