N = 110
w = [[0] * N for i in range(N)]
f = [[0] * N for i in range(N)]
t = int(input())
while t:
n, m = map(int, input().split())
for i in range(n):
w[i] = list(map(int, input().split()))
for i in range(n):
for j in range(m):
f[i][j] = max(f[i-1][j], f[i][j-1]) + w[i][j]
print(f[n-1][m -1])
t -= 1