#include <iostream>
#include <cstring>
using namespace std;
const int N = 110;
int n;
int r, c;
int t;
int f[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n ;
while(n--)
{
cin >> r >> c;
memset(f, 0, sizeof(f));
for(int i=1; i<=r; i++)
{
for(int j=1; j<=c; j++)
{
cin >> t;
f[j] = max(f[j-1], f[j]) + t;
}
}
cout << f[c] << endl;
}
return 0;
}