405177: GYM101810 E N-Dimensional Grid

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. N-Dimensional Gridtime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You are given an n-dimensional grid in which the dimensions of the grid are a1 × a2 × ... × an. Each cell in the grid is represented as an n-tuple (x1, x2, ..., xn) (1 ≤ xi ≤ ai).

Two cells are considered to be adjacent if the Manhattan Distance between them is equal to 1. The Manhattan Distance between two cells X(x1, x2, ..., xn) and Y(y1, y2, ..., yn) is equal to: |x1 - y1| + |x2 - y2| + ... + |xn - yn|.

Your task is to count how many pairs of cells are adjacents. Can you? Two pairs of cells are considered the same if they include the same cells, i.e the pair (c1, c2) is the same as (c2, c1).

Input

The first line contains an integer T (1 ≤ T ≤ 100) specifying the number of test cases.

The first line of each test case contains an integer n (1 ≤ n ≤ 105), in which n is the number of dimensions of the grid. Then a line follows containing n integers a1, ..., an (1 ≤ ai ≤ 105), in which ai is the size of the ith dimension.

The sum of n overall test cases does not exceed 6 × 106.

Output

For each test case, print a single line containing the number of pairs of adjacent cells modulo 109 + 7.

ExampleInput
1
3
1 2 3
Output
7
Note

The absolute value |x| of a real number x is the non-negative value of x without regard to its sign. Namely, |x| = x for a positive x, |x| =  - x for a negative x (in which case  - x is positive), and |0| = 0. For example, the absolute value of 3 is 3, and the absolute value of  - 3 is also 3. The absolute value of a number may be thought of as its distance from zero.

加入题单

上一题 下一题 算法标签: