#include <iostream>
#include <cstring>
using namespace std;
const int N = 10;
int mp[N][N];
int st[N][N];
int T, n, m;
int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int ans;
void dfs(int x, int y,int res){
if(x == n + 1){
ans = max(res, ans);
return;
}
if(y == m + 1){
dfs(x + 1, 1, res);
return;
}
dfs(x, y+1, res);
if(st[x][y]) return;
for (int i = 0; i < 8; i ++ ){
int xx = x + dx[i];
int yy = y + dy[i];
st[xx][yy] ++;
}
dfs(x, y + 1, res + mp[x][y]);
for (int i = 0; i < 8; i ++ ){
int xx = x + dx[i];
int yy = y + dy[i];
st[xx][yy] --;
}
}
int main(){
cin >> T;
while(T --){
memset(st, 0, sizeof st);
cin >> n >> m;
ans = 0;
for (int i = 1; i <= n; i ++ ){
for (int j = 1; j <= m; j ++ ) cin >> mp[i][j];
}
dfs(1, 1, 0);
cout << ans << endl;
}
return 0;
}