public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		for (int i = 0; i < n; i++) {
			String[] in = br.readLine().split(" ");
			int row = Integer.parseInt(in[0]);
			int col = Integer.parseInt(in[1]);
			int[][] input = new int[row][col];
			int[][] max_stones = new int[row][col];
			for (int j = 0; j < row; j++) {
				String[] rowIn = br.readLine().split(" ");
				for (int k = 0; k < col; k++) {
					input[j][k] = Integer.parseInt(rowIn[k]);
				}
			}
			int max = 0;
			for (int j = 0; j < row; j++) {
				for (int k = 0; k < col; k++) {
					max_stones[j][k] = getMaxStones(j, k, max_stones) + input[j][k];
					max = max > max_stones[j][k] ? max : max_stones[j][k];
				}
			}
			System.out.println(max);
		}
	}