import java.util.*;
class Main{
public static void main(String[] args) {
Scanner in =new Scanner(System.in);
int m=in.nextInt();
while(m–!=0) {
int n=in.nextInt();
int k=in.nextInt();
int a[][]=new int [n+1][k+1];
int f[][]=new int [n+1][k+1];
for(int i=1;i<=n;i) {
for(int j=1;j<=k;j) {
a[i][j]=in.nextInt();
}
}
for(int i=1;i<=n;i) {
for(int j=1;j<=k;j) {
f[i][j]+=Math.max(f[i][j-1], f[i-1][j])+a[i][j];
}
}
System.out.println(f[n][k]);
}
}
}