In the qualification rounds of the World Cup, there were two disjoint sets of teams S1 = [1, ..., N] and S2 = [1, ..., M]. Given a matrix X that decides the importance of the match between team
against team
by the value Xi, j. S1 represents the rows of the matrix X, and S2 represents the columns of the matrix X. We would like to answer Q queries, where each decides the importance of all the matches played by all the teams from the subgroup [A, ..., C] from S1 against all teams from the subgroup [B, ..., D] from S2, such that 1 ≤ A ≤ C ≤ N, 1 ≤ B ≤ D ≤ M. The importance of a set of matches between two subgroups is determined by the median importance of all the matches between the teams from the first subgroup against all the teams from the second group, namely the median of the submatrix XA... C, B... D.
The first line of the input contains a single integer 1 ≤ T ≤ 100 the number of test cases. Each test case begins with a line containing 3 spaces separated integers N, M, Q. The importance matrix X is given by the next N lines each containing M space separated integers. The remaining Q lines, each contains 4 space separated integers A, B, C, D of the query; where 1 ≤ N, M ≤ 200, 1 ≤ Q ≤ 10000, and for the given importance matrix X, 1 ≤ Xi, j ≤ 2000 for all i, j.
For each test case output a line displaying the case number, followed by Q lines each containing a single integer, the importance of the matches of the corresponding query.
1
3 4 2
1 2 3 1
2 1 1 4
7 8 9 3
1 1 1 1
1 2 3 4
Case 1:
1
3
| Название |
|---|


