Given a matrix �A with �n rows and �m columns, your ob
A square matrix �B is designated as diagonal fancy if it satisfies the subsequent criteria:
Here, ��,�Bi,j signifies the element located at the �i-th row and �j-th column of matrix �B.
A continuous sub-square matrix from matrix �A with �n rows and �n columns is defined as the matrix derived from �A by selecting continuous �n rows and continuous �n columns.
Ensure to use cin/cout and disable synchronization with stdio to avoid unexpected TLE verdict.
The input consists of multiple test cases. The first line of the input contains an integer �T (1≤�≤1001≤T≤100), which represents the number of test cases.
The first line of each test case contains two integers �n and �m (1≤�,�≤10001≤n,m≤1000), representing the number of rows and columns in the matrix �A.
Each of the next �n lines contains �m space-separated integers ��,1,��,2,…,��,�Ai,1,Ai,2,…,Ai,m (1≤��,�≤�×�1≤Ai,j≤n×m), representing the elements of the matrix �A for that particular test case.
It is guaranteed that ∑�×�≤107∑n×m≤107 over all test cases.
3
2 2
1 2
3 1
2 2
1 2
2 1
3 3
1 2 3
4 1 2
5 4 1
5
4
14