#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
typedef long long int ll;
ll t, n, m, mat[50][50], minim_rowarr[50][50][50], ans_row[50][50][50], ans_col[50][50][50], minim_colarr[50][50][50], ans[50][50][50][50], minim_ans[50][50][50][50];
ll solve_row(int row, int a, int b)
{
if (ans_row[row][a][b] != -1)
return ans_row[row][a][b];
if (a == b)
return 0;
ll minim = 110000;
for (int i = a; i <= b; i++)
minim = min(minim, mat[row][i]);
minim_rowarr[row][a][b] = minim;
minim_ans[row][a][row][b] = minim;
ll maxim = 0;
for (int i = a; i < b; i++)
{
maxim = max(solve_row(row, a, i)+solve_row(row, i+1, b), maxim);
}
ans_row[row][a][b] = maxim+minim;
ans[row][a][row][b] = maxim+minim;
return (maxim+minim);
}
ll solve_col(int col, int a, int b)
{
if (ans_col[col][a][b] != -1)
return ans_col[col][a][b];
if (a == b)
return 0;
ll minim = 110000;
for (int i = a; i <= b; i++)
minim = min(minim, mat[i][col]);
minim_colarr[col][a][b] = minim;
minim_ans[a][col][b][col] = minim;
ll maxim = 0;
for (int i = a; i < b; i++)
{
maxim = max(solve_col(col, a, i)+solve_col(col, i+1, b), maxim);
}
ans_col[col][a][b] = maxim+minim;
ans[a][col][b][col] = maxim+minim;
return (maxim+minim);
}
int main()
{
ios::sync_with_stdio(false);
cin>>t;
for (int i = 1; i <= t; i++)
{
memset(ans_row, -1, sizeof(ans_row));
memset(ans_col, -1, sizeof(ans_col));
memset(ans, 0, sizeof(ans));
memset(minim_ans, 0, sizeof(minim_ans));
memset(minim_rowarr, 0, sizeof(minim_rowarr));
memset(minim_colarr, 0, sizeof(minim_colarr));
memset(mat, 0, sizeof(mat));
cin>>n>>m;
for (int j = 1; j <= n; j++)
{
for (int k = 1; k <= m; k++)
{
cin>>mat[j][k];
}
solve_row(j, 1, m);
}
for (int j = 1; j <= m; j++)
{
solve_col(j, 1, n);
}
for (int j = 1; j <= n; j++)
{
for (int k = 1; k <= m; k++)
{
for (int l = j-1; l >= 1; l--)
{
for (int y = k-1; y >= 1; y--)
{
ll maxim_ans = 0;
ll minim = min(minim_ans[l][y+1][j][k], minim_ans[l][y][j][y]);
minim_ans[l][y][j][k] = minim;
for (int z = j; z > l; z--)
{
maxim_ans = max(maxim_ans, (ans[l][y][z-1][k]+ans[z][y][j][k]));
}
for (int z = k; z > y; z--)
{
maxim_ans = max(maxim_ans, (ans[l][y][j][z-1]+ans[l][z][j][k]));
}
ans[l][y][j][k] = maxim_ans+minim;
}
}
}
}
ll ans1 = ans[1][1][n][m];
cout<<"Case #"<<i<<": "<<ans1<<"\n";
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdHlwZWRlZiBsb25nIGxvbmcgaW50IGxsOwpsbCB0LCBuLCBtLCBtYXRbNTBdWzUwXSwgbWluaW1fcm93YXJyWzUwXVs1MF1bNTBdLCBhbnNfcm93WzUwXVs1MF1bNTBdLCBhbnNfY29sWzUwXVs1MF1bNTBdLCBtaW5pbV9jb2xhcnJbNTBdWzUwXVs1MF0sIGFuc1s1MF1bNTBdWzUwXVs1MF0sIG1pbmltX2Fuc1s1MF1bNTBdWzUwXVs1MF07CmxsIHNvbHZlX3JvdyhpbnQgcm93LCBpbnQgYSwgaW50IGIpCnsKCWlmIChhbnNfcm93W3Jvd11bYV1bYl0gIT0gLTEpCgkJcmV0dXJuIGFuc19yb3dbcm93XVthXVtiXTsKCWlmIChhID09IGIpCgkJcmV0dXJuIDA7CglsbCBtaW5pbSA9IDExMDAwMDsKCWZvciAoaW50IGkgPSBhOyBpIDw9IGI7IGkrKykKCQltaW5pbSA9IG1pbihtaW5pbSwgbWF0W3Jvd11baV0pOwoJbWluaW1fcm93YXJyW3Jvd11bYV1bYl0gPSBtaW5pbTsKCW1pbmltX2Fuc1tyb3ddW2FdW3Jvd11bYl0gPSBtaW5pbTsKCWxsIG1heGltID0gMDsKCWZ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