Problem 1216 --Magic Matrix## 1216: Magic Matrix

Time Limit: 2 Sec Memory Limit: 256 MB

Submit: 172 Solved: 36

[Submit][Status][Web Board]## Description

A matrix is magic , if the difference between its maxmium and mimimum elements ≤ m.
IceRuler has a large N×N matrix M. He would like to know size of the biggest magic sub-matrix of M.

## Input

Input contains multiple testcases. The first line of Input contains a single integer T（ 1≤T≤1000）.The number of testcases.
For each case，first line contains two numbers N (1≤N≤500) and M(0≤M≤100000)，represent the given matrix is N square matrix and magic equilibrium value is M.
Each of the next N rows contains N integers, representing the large matrix. Elements are positive integers and not larger than \(10^5\) .
It is guaranteed that the sum of \(N^3\) for all testcases is not exceed \(2\cdot 10^8\) 。

## Output

For each case, print size of the biggest magic sub-matrix of M in one line.

## Sample Input

2
2 0
3 3
2 3
3 1
2 4 3
3 4 2
4 3 2

## Sample Output

2
4

## HINT

## Source

[Submit][Status]