// SPOJ BYTESM2
#include <iostream>
#include <conio.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define maxN 100
int h, w;
int stones[maxN][maxN];
int main()
{
freopen("input.txt", "r", stdin);
int T;
cin >> T;
FOR(testcase, 1, T)
{
cin >> h >> w;
FOR(row, 1, h)
{
FOR(col, 1, w)
{
cin >> stones[row][col];
if(row > 1)
{
int left = 0, right = 0, above = 0;
if(col > 1)
left = stones[row-1][col-1];
if(col < w)
right = stones[row-1][col+1];
above = stones[row-1][col];
int max = above;
max = max > left ? max : left;
max = max > right ? max : right;
stones[row][col] += max;
}
}
}
int maxStone = 0;
FOR(col, 1, w)
if(stones[h][col] > maxStone)
maxStone = stones[h][col];
cout << maxStone << endl;
}
getch();
return 0;
}