https://www.acwing.com/problem/content/1017/
#include<bits/stdc++.h>
using namespace std;
const int N=110;
int t,r,c;
int ans[N][N];
int main(){
cin>>t;
while(t--){
cin>>r>>c;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++)
scanf("%d",&ans[i][j]);
}
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
ans[i][j]=max(ans[i-1][j],ans[i][j-1])+ans[i][j];
}
}
cout<<ans[r][c]<<endl;
}
return 0;
}