#include <cstdio>
#include <algorithm>
using namespace std;
int t, n, m, i, j, ans;
int a[1005][1005], f[1005][1005];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &a[i][j]);
}
}
ans = a[n][m];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + a[n - i + 1][m - j + 1];
ans = max(ans, f[i][j]);
}
}
printf("%d\n", ans);
}
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgdCwgbiwgbSwgaSwgaiwgYW5zOwppbnQgYVsxMDA1XVsxMDA1XSwgZlsxMDA1XVsxMDA1XTsKCmludCBtYWluKCkgewoJc2NhbmYoIiVkIiwgJnQpOwoJd2hpbGUgKHQtLSkgewoJCXNjYW5mKCIlZCVkIiwgJm4sICZtKTsKCQlmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKCQkJZm9yIChpbnQgaiA9IDE7IGogPD0gbTsgaisrKSB7CgkJCQlzY2FuZigiJWQiLCAmYVtpXVtqXSk7CgkJCX0KCQl9CgkJYW5zID0gYVtuXVttXTsKCQlmb3IgKGludCBpID0gMTsgaSA8PSBuOyBpKyspIHsKCQkJZm9yIChpbnQgaiA9IDE7IGogPD0gbTsgaisrKSB7CgkJCQlmW2ldW2pdID0gZltpIC0gMV1bal0gKyBmW2ldW2ogLSAxXSAtIGZbaSAtIDFdW2ogLSAxXSArIGFbbiAtIGkgKyAxXVttIC0gaiArIDFdOwoJCQkJYW5zID0gbWF4KGFucywgZltpXVtqXSk7CgkJCX0KCQl9CgkJcHJpbnRmKCIlZFxuIiwgYW5zKTsKCX0KCXJldHVybiAwOwp9