Little Tommy is playing a game. The game is played on a 2D N x N grid. There is an integer in each cell of the grid. The rows and columns are numbered from 1 to N.
At first the board is shown. When the user presses a key, the screen shows three integers i, j, s which designates a square (i, j) to (i + s - 1, j + s - 1) on the grid. The player has to predict the largest integer found in this square. The user will be given points based on the difference between the actual result and the given result.
Tommy doesn't like to lose. So, he made a plan, he will take help of a computer to generate the result. But since he is still learning programming, he is seeking your help.
Input
Input starts with an integer T (< 5), denoting the number of test cases.
The first line of a case is a blank line. The next line contains two integers N (1 ≤ N ≤ 500), Q (0 ≤ Q ≤ 50000). Each of the next N lines will contain N space separated integers forming the grid. All the integers will be between 0 and 105.
Each of the next Q lines will contain a query which is in the form i j s (1 ≤ i, j ≤ N and 1 ≤ i + s -1, j + s - 1 ≤ N and s > 0).
Output
For each test case, print the case number in a single line. Then for each query you have to print the maximum integer found in the square whose top left corner is (i, j) and whose bottom right corner is (i + s - 1, j + s - 1).
Sample
Sample Input | Sample Output |
---|---|
1 4 5 67 1 2 3 8 88 21 1 89 12 0 12 5 5 5 5 1 1 2 1 3 2 3 3 2 1 1 4 2 2 3 | Case 1: 88 21 12 89 88 |
Notes
- Dataset is huge. Use faster I/O methods.
- The given sample corresponds to the following matrix:
$$\begin{bmatrix} 67 & 1 & 2 & 3 \\ 8 & 88 & 21 & 1 \\ 89 & 12 & 0 & 12 \\ 5 & 5 & 5 & 5 \end{bmatrix} $$
For the query 1 3 2
, we get the following sub matrix:
$$\begin{bmatrix} 2 & 3 \\ 21 & 1 \end{bmatrix} $$
And the maximum is 21.