Junk Junction

Time limit: 1s Memory limit: 256MB Input: Output:

Task

In Junk Junction there is an infinite sequence of infinite matrices A1,A2,A3,A_1,A_2,A_3,\ldots, which is defined in the following way:

An[i][j]={0,if j>i1,if ji and n=1k=1jAn1[i][k],if ji and n>1A_n[i][j]=\begin{cases}0, & \text{if $j \gt i$} \\ 1, & \text{if $j \le i$ and $n=1$} \\ \sum_{k=1}^j A_{n-1}[i][k], & \text{if $j \le i$ and $n \gt 1$} \end{cases}

The 5×55 \times 5 upper-left corners of the first 55 matrices will have the following values:

A1=[1000011000111001111011111]A_1 = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 1 & 1 & 0 & 0 & 0 \\ 1 & 1 & 1 & 0 & 0 \\ 1 & 1 & 1 & 1 & 0 \\ 1 & 1 & 1 & 1 & 1 \\ \end{bmatrix}A2=[1000012000123001234012345]A_2 = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 1 & 2 & 0 & 0 & 0 \\ 1 & 2 & 3 & 0 & 0 \\ 1 & 2 & 3 & 4 & 0 \\ 1 & 2 & 3 & 4 & 5 \\ \end{bmatrix}A3=[1000013000136001361001361015]A_3 = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 1 & 3 & 0 & 0 & 0 \\ 1 & 3 & 6 & 0 & 0 \\ 1 & 3 & 6 & 10 & 0 \\ 1 & 3 & 6 & 10 & 15 \\ \end{bmatrix}A4=[1000014000141000141020014102035]A_4 = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 1 & 4 & 0 & 0 & 0 \\ 1 & 4 & 10 & 0 & 0 \\ 1 & 4 & 10 & 20 & 0 \\ 1 & 4 & 10 & 20 & 35 \\ \end{bmatrix}A5=[1000015000151500151535015153570]A_5 = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 1 & 5 & 0 & 0 & 0 \\ 1 & 5 & 15 & 0 & 0 \\ 1 & 5 & 15 & 35 & 0 \\ 1 & 5 & 15 & 35 & 70 \\ \end{bmatrix}

Given 55 integers nn, i1i_1, j1j_1, i2i_2 and j2j_2, determine the value of:

i=i1i2j=j1j2An[i][j]\sum_{i=i_1}^{i_2}\sum_{j=j_1}^{j_2}A_n[i][j]

Since the answer can be very large, print its remainder modulo 109+710^9+7.

Input data

The first line of input contains a single integer tt (1t1051 \le t \le 10^5) - the number of test cases.

The first (and only) line of each test case contains 55 integers nn, i1i_1, j1j_1, i2i_2 and j2j_2 (1n,i1,j1,i2,j21061 \le n ,i_1,j_1,i_2,j_2 \le 10^6, i1i2i_1 \le i_2, j1j2j_1 \le j_2).

Output data

For each test case, print the sum of the elements from the corresponding submatrix.

Since the answer can be very large, print its remainder modulo 109+710^9+7.

Example

stdin

6
2 2 1 4 4
1 3 2 4 5
3 1 1 5 5
5 3 2 5 4
1000000 1 2 1 1000000
15 11 9 25 20

stdout

19
5
70
130
0
335165324

Explanation

In the first test case, the submatrix from A2A_2 whose corners are in (2,1)(2,1), and (4,4)(4,4), respectively, contains the following values:

[120012301234]\begin{bmatrix} 1 & 2 & 0 & 0 \\ 1 & 2 & 3 & 0 \\ 1 & 2 & 3 & 4 \\ \end{bmatrix}

The sum of these values is equal to: 1+1+1+2+2+2+3+3+4=191+1+1+2+2+2+3+3+4=19.

In the second test case, the submatrix from A1A_1 whose corners are in (3,2)(3,2), and (4,5)(4,5), respectively, contains the following values:

[11001110]\begin{bmatrix} 1 & 1 & 0 & 0 \\ 1 & 1 & 1 & 0 \\ \end{bmatrix}

The sum of these values is equal to: 1+1+1+1+1=51+1+1+1+1=5.

Log in or sign up to be able to send submissions!