#include<bits/stdc++.h>
using namespace std;
int a[10][10];
int state[10][10]={};
int t,n,m,ans;;
void dfs(int x, int y, int sum){
int i;
if (y>m){
x++;
y=1;
}
if (x>n){
if (sum>ans)
ans=sum;
return;
}
dfs(x,y+1,sum);
if (state[x][y-1]==0 && state[x-1][y-1]==0 && state[x-1][y]==0 && state[x-1][y+1]==0){
state[x][y]==1;
dfs(x,y+1,sum+a[x][y]);
state[x][y]=0;
}
return;
}
int main(){
int i,j,k;
cin >> t;
for (k=1;k<=t;k++){
cin >> n >> m;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
cin >> a[i][j];
ans=0;
dfs(1,1,0);
cout << ans << endl;
}
return 0;
}