#include<bits/stdc++.h>
using namespace std;
int n,m,t;
int g[10][10];
bool st[10][10];
int res;
int dx[8]={-1,-1,-1,0,1,1,1,0};
int dy[8]={-1,0,1,1,1,0,-1,-1};
bool check(int x,int y){
for(int i=0;i<8;i++){
int a=x+dx[i],b=y+dy[i];
if(st[a][b])
return false;
}
return true;
}
void dfs(int sum,int ii,int jj){
if(jj>m) jj=1,ii++;
if(ii>n) return ;
res=max(res,sum);
for(int i=ii;i<=n;i++){
for(int j=jj;j<=m;j++){
if(check(i,j)){
st[i][j]=true;
//for(int iw=1;iw<=n;iw++){ for(int jw=1;jw<=m;jw++) if(st[iw][jw]) cout<<-1<<' '; else cout<<g[iw][jw]<<' '; cout<<endl; }
// cout<<endl;
dfs(sum+g[i][j],i,j+2);
st[i][j]=false;
}
}
}
}
int main(){
cin>>t;
while(t--){
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>g[i][j];
res=0;
dfs(0,1,1);
memset(st,false,sizeof st);
cout<<res<<endl;
}
}
求大佬指点