Planting Trees
题号:NC51449
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

The semester is finally over and the summer holiday is coming. However, as part of your university's graduation requirement, you have to take part in some social service during the holiday. Eventually, you decided to join a volunteer group which will plant trees in a mountain.

To simplify the problem, let's represent the mountain where trees are to be planted with an grid. Let's number the rows to from top to bottom, and number the columns to from left to right. The elevation of the cell in the-th row and-th column is denoted by . Your leader decides that trees should be planted in a rectangular area within the mountain and that the maximum difference in elevation among the cells in that rectangle should not exceed M. In other words, if the coordinates of the top-left and the bottom-right corners of the rectangle are (x_1,y_1) and (x_2,y_2), then the condition must hold for . Please help your leader calculate the maximum possible number of cells in such a rectangle so that he'll know how many trees will be planted.

输入描述:

The input contains multiple cases. The first line of the input contains a single integer , the number of cases.
For each case, the first line of the input contains two integers and . The following N lines each contain N integers, where the-th integer in the-th line denotes .
It is guaranteed that the sum of over all cases does not exceed .

输出描述:

For each case, print a single integer, the maximum number of cells in a valid rectangle.
示例1

输入

复制
2
2 0
1 2
2 1
3 1
1 3 2
2 3 1
3 2 1

输出

复制
1
4