#include<bits/stdc++.h>
using namespace std;
int n,m,e,r;int a[100][100];bool t[100][100];
void f(int x,int y)
{
if (x>n)
{if (e>=r)
{
r=e;
}
return ;}
if (y+1>m)
f(x+1,1);
else f(x,y+1);
if (t[x][y]==0)
{e+=a[x][y];
t[x][y]=1;
t[x-1][y]=1;
t[x+1][y]=1;
t[x][y+1]=1;
t[x][y-1]=1;
t[x-1][y-1]=1;
t[x-1][y+1]=1;
t[x+1][y-1]=1;
t[x+1][y+1]=1;
if (y+1>m)
{f(x+1,1);e-=a[x][y];}
else {
f(x,y+1);e-=a[x][y];}
t[x][y]=0;
t[x-1][y]=0;
t[x+1][y]=0;
t[x][y+1]=0;
t[x][y-1]=0;
t[x-1][y-1]=0;
t[x-1][y+1]=0;
t[x+1][y-1]=0;
t[x+1][y+1]=0;}
return ;
}
int main()
{int w,g;
cin>>g;
for (int i=1;i<=g;i++)
{cin>>n>>m;e=0;r=-1;
for (int j=1;j<=n;j++)
{for (int k=1;k<=m;k++)
{cin>>a[j][k];}}
f(1,1);
cout<<r<<"\n";}
return 0;}