#include<iostream>
#include<algorithm>
using namespace std;
const int N = 105;
int arr[N][N],dp[N][N];
int T,m,n;//T组用例,棋盘为m行n列
int main() {
cin >> T;
while (T--) {
cin >> m >> n;
for (int i = 1;i <= m;i++) {
for (int j = 1;j <= n;j++) {
cin >> arr[i][j];
}
}
for (int i = 1;i <= m;i++) {
for (int j = 1;j <= n;j++) {
dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]) + arr[i][j];
}
}
cout << dp[m][n] << endl;
}
}