#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int main(){
int T;
cin>>T;
while(T--){
int R, C;
cin>>R>>C;
int M[R+1][C+1];
memset(M, 0x00, sizeof M);
for(int i=1; i<=R; ++i)
for(int j=1; j<=C; ++j)
cin>>M[i][j];
int f[R+1][C+1];
memset(f, 0x00, sizeof f);
for(int i=1; i<=R; ++i)
for(int j=1; j<=C; ++j)
f[i][j] = max(f[i-1][j], f[i][j-1])+M[i][j];
cout<<f[R][C]<<endl;
}
return 0;
}