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