Diamond Rush

아직 제출이 없습니다시간 제한4초메모리 제한512 MB

문제

There are n×nn \times n cells on a grid, the top-left cell is at (1,1)(1,1) while the bottom-right cell is at (n,n)(n,n). In the cell (i,j)(i,j) which is at row ii and column jj, there are (n2)a_i,j\left(n^2\right)^{a\_{i,j}} diamonds.

You start at (1,1)(1,1) and move to (n,n)(n,n). At any cell (i,j)(i,j), you can move to (i+1,j)(i+1,j) or (i,j+1)(i,j+1), provided that you don't move out of the grid. Clearly, you will make exactly 2n22n-2 steps. When you are at a cell, you can take all the diamonds at this cell, including the starting point (1,1)(1,1) and the destination (n,n)(n,n).

However, some cells are blocked, but you don't know which cells are blocked. Please write a program to answer qq queries. In each query, you will be given four integers r_1r\_1, r_2r\_2, c_1c\_1, c_2c\_2, and you need to report the maximum number of diamonds that you can take without passing the cells (i,j)(i,j) such that r_1ir_2r\_1 \leq i \leq r\_2 and c_1jc_2c\_1 \leq j \leq c\_2.

입력

The first line contains a single integer TT (1T51 \leq T \leq 5), the number of test cases. For each test case:

The first line contains two integers nn and qq (2n4002 \leq n \leq 400, 1q200,0001 \leq q \leq 200\\,000) denoting the size of the grid and the number of queries.

Each of the following nn lines contains nn integers, the ii-th line contains a_i,1,a_i,2,,a_i,na\_{i,1},a\_{i,2},\dots,a\_{i,n} (1a_i,jn21\leq a\_{i,j}\leq n^2) denoting the number of diamonds in each cell.

Each of the following qq lines contains four integers r_1r\_1, r_2r\_2, c_1c\_1, c_2c\_2 (1r_1r_2n1 \leq r\_1 \leq r\_2 \leq n, 1c_1c_2n1 \leq c\_1 \leq c\_2 \leq n) describing a query. It is guaranteed that you can find at least one valid path in each query.

출력

For each query, print a single line containing an integer: the maximum number of diamonds that you can take. Note that the answer may be extremely large, so please print it modulo 109+710^9+7 instead.