#include<iostream>
using namespace std;
const int N = 110;
int t;
int f[N][N];
int main(){
cin>>t;
while(t--)
{
int a,b;cin>>a>>b;
for(int i=1;i<=a;i++)
for(int j=1;j<=b;j++)
cin>>f[i][j];
for(int i=1;i<=a;i++)
{
for(int j=1;j<=b;j++)
{
f[i][j] = f[i][j] + max(f[i-1][j], f[i][j-1]);
}
}
cout<<f[a][b]<<endl;
}
return 0;
}