#include #include #include #include #include #include #define MAXN 505 #define INF 1000000007 using namespace std; const int dir[4][2]={{1,1},{-1,1},{1,-1},{-1,-1}}; int n, m,ans; int dp[MAXN][MAXN][4],to[4]={3,2,1,0}; char st[MAXN][MAXN]; long long p[MAXN], r[MAXN][MAXN], c[MAXN][MAXN]; void cal(int x,int y,int k) { int now=dp[x][y][k]; x+=dir[k][0],y+=dir[k][1]; while(x>=0&&x=0&&y=now+2) now+=2; else ++now; ans=max(now,ans); x+=dir[k][0],y+=dir[k][1]; } } long long ac1(int rr,int x,int y) { int l=y-x+1; if (!x) return r[rr][y]; return r[rr][y]-r[rr][x-1]*p[l]; } long long ac2(int cc,int x,int y) { int l=y-x+1; if (!x) return c[cc][y]; return c[cc][y]-c[cc][x-1]*p[l]; } int main() { int cas; scanf("%d",&cas); p[0]=1; for (int i=1;i<=500;i++) p[i]=p[i-1]*131; while (cas--) { ans=1; scanf("%d%d",&n,&m); for (int i=0;i