
For the matrices 'MAT1' and 'MAT2' as shown in the image below, the largest sub-square which is common in both of the matrices is of size 2.

If there is no such sub-square present then return 0.
The first line of input contains an integer 'T’ denoting the number of test cases. Then each test case follows.
The first line of each test case contains two single space-separated integers ‘N1’ and ‘M1’ representing the size of the matrix ‘MAT1’.
The next ‘N1’ lines of each test case contain ‘M1’ single space-separated integers denoting the values of ‘MAT1’.
The next line of each test case contains two single space-separated integers ‘N2’ and ‘M2’ representing the size of the matrix ‘MAT2’.
The next ‘N2’ lines of each test case contain ‘M2’ single space-separated integers denoting the values of ‘MAT2’.
For each test case, print a single line containing a single integer denoting the size of the largest possible sub-square which is also present in another matrix.
The output of each test case will be printed in a separate line.
You are not required to print the expected output; it has already been taken care of. Just implement the function.
1 <= ‘T’ <= 100
1 <= ‘N1, ‘M1’, ‘N1’, ‘M2’ <= 50
1 <= ‘MAT1[ i ][ j ]’, ‘MAT2[ i ][ j ]’ <=10000
Time limit: 1 sec.
Hashing will allow us to represent the whole sub-square as a single number. Then for comparing the sub-square present in both the matrices, we just compare the corresponding numbers. We make hash matrices ‘HashMatA’ and ‘HashMatB’ corresponding to the input matrices ‘MAT1’ and ‘MAT2’. We use the idea of the Rabin-karp pattern matching algorithm and modify it for calculating the hash value which is a single number representing 2-D matrices.
Here is the algorithm :