// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
using namespace std;
// mylittledoge
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
for(int t =0; t < T; t++) {
int N,M;
cin >> N >> M;
vector< vector<int> > A(N,vector<int>(M));
for(int i =0; i < N; i++)
for(int j =0; j < M; j++) cin >> A[i][j];
int ans =min(N,2)*min(M,2);
vector<int> H0(M,0),H(M,0); // vyska obdlznika sirky 1,3
for(int i =0; i < N; i++) {
stack< pair<int,int> > S; // sirka aspon 3
for(int j =0; j < M; j++) {
H0[j]++;
if(i > 1 && A[i][j]-A[i-1][j] != A[i-1][j]-A[i-2][j]) H0[j] =2;
ans =max(ans,H0[j]);
if(j > 0) ans =max(ans,min(H0[j],H0[j-1])*2);
H[j]++;
H[j] =min(H[j],H0[j]);
if(j > 0) H[j] =min(H[j],H0[j-1]);
if(j > 1) H[j] =min(H[j],H0[j-2]);
if(j > 1 && A[i][j]-A[i][j-1] != A[i][j-1]-A[i][j-2]) H[j] =0;
if(j <= 1) continue;
// pridam panel napravo, co nepasuje?
int x =j-2;
while(!S.empty() && S.top().ff > H[j]) {
ans =max(ans,(j-S.top().ss)*S.top().ff);
x =S.top().ss;
S.pop();}
if(S.empty() || S.top().ff != H[j]) if(H[j] > 0) S.push(make_pair(H[j],x));}
while(!S.empty()) {
ans =max(ans,(M-S.top().ss)*S.top().ff);
S.pop();}
}
cout << ans << "\n";}
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMg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