#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[110][110];
int a[110][110];
int main()
{
int t;
cin >> t;
while(t--)
{
memset(dp,0,sizeof dp);
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
cin >> a[i][j];
}
}
dp[1][1] = a[1][1];
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
dp[i][j] = a[i][j] + max(dp[i-1][j], dp[i][j-1]);
}
}
cout << dp[n][m] << endl;
}
return 0;
}