#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<lint, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
const int MAXN = 105;
// n^
// d[i, h] -> d[i + 1, h]
// d[j, h ^ sum[i, j]]
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc;
cin >> tc;
for (int i = 1; i <= tc; i++) {
cout << "Case #" << i << ": ";
int n, m;
cin >> n >> m;
vector<vector<lint>> a(n + 2, vector<lint>(m + 2));
vector<vector<lint>> d1(n + 2, vector<lint>(m + 2));
vector<vector<lint>> d2(n + 2, vector<lint>(m + 2));
vector<vector<lint>> up(n + 2, vector<lint>(m + 2, 1e18));
vector<vector<lint>> le(n + 2, vector<lint>(m + 2, 1e18));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
d1[i][j] = max(d1[i][j - 1], d1[i - 1][j]) + a[i][j];
}
}
for (int i = n; i > 0; i--) {
for (int j = m; j > 0; j--) {
d2[i][j] = max(d2[i][j + 1], d2[i + 1][j]) + a[i][j];
}
}
up[1][m] = le[1][m] = -1e18;
for (int i = 1; i <= n; i++) {
for (int j = m; j >= 1; j--) {
{
lint d1max = d1[i - 1][j], summax = -1e18;
for (int k = i + 1; k <= n; k++) {
d1max = max(d1max, d1[k - 1][j - 1]);
if (k > i + 1)
summax = max(summax, d1max + d2[k - 1][j + 1]);
up[k][j] = min(up[k][j], max({d1max + max(d2[k + 1][j], d2[k][j + 1]), summax, le[i][j]}));
}
}
{
lint d2max = d2[i][j + 1], summax = -1e18;
for (int l = j - 1; l >= 1; l--) {
d2max = max(d2max, d2[i + 1][l + 1]);
if (l < j - 1)
summax = max(summax, d2max + d1[i - 1][l + 1]);
le[i][l] = min(le[i][l], max({d2max + max(d1[i][l - 1], d1[i - 1][l]), summax, up[i][j]}));
}
}
}
}
cout << min(up[n][1], le[n][1]) << "\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