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.
Example
Input
1
3
1 2 3
Output
7
题意:
在一个 n 维空间中的一个点可以表示为一个 n 元组 (a1,a2,a3,a4,a5,…,an)
两个格子相邻时:这两个格子的曼哈顿距离为1,即对于两个点
typedeflonglong ll; ll ans; const ll MOD = 1000000000 + 7; int a[100000 + 10]; intmain() { int T; scanf("%d", &T); while (T--) { memset(a,0, sizeof(a)); int n; ans = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } ll num = a[0]; ans = a[0] - 1;//第一维 for (int i = 1; i < n; i++) { ans = ans * a[i]; ans %= MOD; ans = ans + (a[i] - 1)*num; num *= a[i]; num %= MOD; ans %= MOD; } printf("%lld\n", ans); } }