#include<iostream>
#include<cstring>
using namespace std;
int n,m;
int a[10][10] = {0};
int map[10][10] = {0};
int maxx = 0;
void dfs(int x,int y,int sum){
maxx = max(maxx,sum);、
int my = y+1;
int mx = x;
if(my>m){
my = 1;
mx = x+1;
}
if(mx>n) return;
if(!map[mx-1][my-1]&&!map[mx][my-1]&&!map[mx+1][my-1]&&!map[mx-1][my]&&!map[mx+1][my]&&!map[mx-1][my+1]&&!map[mx][my+1]&&!map[mx+1][my+1]){
map[mx][my]=1;
dfs(mx,my,sum+a[mx][my]);
map[mx][my]=0;
}
dfs(mx,my,sum);
return;
}
int main(){
int t;
cin>>t;
for(int i=1;i<=t;i++){
cin>>n>>m;
memset(a,0,sizeof(a));
maxx=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
memset(map,0,sizeof(map));
dfs(1,1,0);
memset(map,0,sizeof(map));
map[1][1]=1;
dfs(1,1,a[1][1]);
cout<<maxx<<endl;
}
return 0;
}