#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
template<class T> struct cLtraits_identity{
using type = T;
}
;
template<class T> using cLtraits_try_make_signed =
typename conditional<
is_integral<T>::value,
make_signed<T>,
cLtraits_identity<T>
>::type;
template <class S, class T> struct cLtraits_common_type{
using tS = typename cLtraits_try_make_signed<S>::type;
using tT = typename cLtraits_try_make_signed<T>::type;
using type = typename common_type<tS,tT>::type;
}
;
template<class S, class T> inline auto min_L(S a, T b)
-> typename cLtraits_common_type<S,T>::type{
return (typename cLtraits_common_type<S,T>::type) a <= (typename cLtraits_common_type<S,T>::type) b ? a : b;
}
inline int my_getchar_unlocked(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread_unlocked(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar_unlocked();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar_unlocked();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
inline int rd_int(void){
int x;
rd(x);
return x;
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite_unlocked(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
template<class T> inline void wt_L(vector<T> x);
template<class T> inline void wt_L(set<T> x);
template<class T> inline void wt_L(multiset<T> x);
template<class T1, class T2> inline void wt_L(pair<T1,T2> x);
inline void wt_L(char a){
my_putchar_unlocked(a);
}
inline void wt_L(int x){
int s=0;
int m=0;
char f[10];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar_unlocked('-');
}
while(s--){
my_putchar_unlocked(f[s]+'0');
}
}
inline void wt_L(const char c[]){
int i=0;
for(i=0;c[i]!='\0';i++){
my_putchar_unlocked(c[i]);
}
}
int main(){
int TEST;
int N;
int W;
int X[101][101];
int val[101][101][101];
int dp[101][101];
int s;
int Nzj9Y0kE = rd_int();
for(TEST=(0);TEST<(Nzj9Y0kE);TEST++){
int i, k;
wt_L("Case #");
wt_L(TEST+1);
wt_L(": ");
rd(N);
rd(W);
{
int QAAnbtfa;
int om7Ebh6q;
for(QAAnbtfa=(0);QAAnbtfa<(N);QAAnbtfa++){
for(om7Ebh6q=(0);om7Ebh6q<(W);om7Ebh6q++){
rd(X[QAAnbtfa][om7Ebh6q]);
}
}
}
for(k=(0);k<(W);k++){
int i;
for(i=(0);i<(N);i++){
int j;
val[k][i][i] = X[i][k];
for(j=(i+1);j<(N);j++){
val[k][i][j] =min_L(val[k][i][j-1], X[j][k]);
}
}
}
for(i=(0);i<(N);i++){
int RlTT0MFE;
remove_reference<decltype(val[RlTT0MFE][i][i])>::type ClGtuHe4;
int BRSo37Cn = 0;
if((0) > ((W)-1)){
ClGtuHe4 = 0;
}
else{
for(RlTT0MFE = 0; RlTT0MFE <= (W)-1; RlTT0MFE++){
if(BRSo37Cn == 0){
ClGtuHe4 = val[RlTT0MFE][i][i];
BRSo37Cn = 1;
continue;
}
ClGtuHe4 += val[RlTT0MFE][i][i];
}
if(BRSo37Cn==0){
ClGtuHe4 = 0;
}
}
dp[i][i] =ClGtuHe4;
}
for(i=(N)-1;i>=(0);i--){
int j;
for(j=(i+1);j<(N);j++){
int U_95anlx;
remove_reference<decltype(val[U_95anlx][i][j])>::type EEPmwYOn;
int hUQRwZho = 0;
if((0) > ((W)-1)){
EEPmwYOn = 0;
}
else{
for(U_95anlx = 0; U_95anlx <= (W)-1; U_95anlx++){
if(hUQRwZho == 0){
EEPmwYOn = val[U_95anlx][i][j];
hUQRwZho = 1;
continue;
}
EEPmwYOn += val[U_95anlx][i][j];
}
if(hUQRwZho==0){
EEPmwYOn = 0;
}
}
s =EEPmwYOn;
int ROdgCjAq;
remove_reference<decltype(dp[i][ROdgCjAq]+dp[ROdgCjAq+1][j]-s)>::type EMcy9lTZ;
int Cn8Hwvol = 0;
if((i) > ((j)-1)){
EMcy9lTZ = numeric_limits<remove_reference<decltype(dp[i][ROdgCjAq]+dp[ROdgCjAq+1][j]-s)>::type>::max();
}
else{
for(ROdgCjAq = i; ROdgCjAq <= (j)-1; ROdgCjAq++){
if(Cn8Hwvol == 0){
EMcy9lTZ = dp[i][ROdgCjAq]+dp[ROdgCjAq+1][j]-s;
Cn8Hwvol = 1;
continue;
}
const auto w83Weq_n = dp[i][ROdgCjAq]+dp[ROdgCjAq+1][j]-s;
if(EMcy9lTZ > w83Weq_n){
EMcy9lTZ = w83Weq_n;
}
}
if(Cn8Hwvol==0){
EMcy9lTZ = numeric_limits<remove_reference<decltype(dp[i][ROdgCjAq]+dp[ROdgCjAq+1][j]-s)>::type>::max();
}
}
dp[i][j] =EMcy9lTZ;
}
}
wt_L(2*dp[0][N-1]);
wt_L('\n');
}
return 0;
}
template<class T> inline void wt_L(vector<T> x){
int fg = 0;
for(auto a : x){
if(fg){
my_putchar_unlocked(' ');
}
fg = 1;
wt_L(a);
}
}
template<class T> inline void wt_L(set<T> x){
int fg = 0;
for(auto a : x){
if(fg){
my_putchar_unlocked(' ');
}
fg = 1;
wt_L(a);
}
}
template<class T> inline void wt_L(multiset<T> x){
int fg = 0;
for(auto a : x){
if(fg){
my_putchar_unlocked(' ');
}
fg = 1;
wt_L(a);
}
}
template<class T1, class T2> inline void wt_L(pair<T1,T2> x){
wt_L(x.first);
my_putchar_unlocked(' ');
wt_L(x.second);
}
// cLay version 20220312-1
// --- original code ---
// int N, W, X[101][101];
// int val[101][101][101], dp[101][101], s;
// REP(TEST,rd_int()){
// wtF("Case #{TEST+1}: ");
// rd(N,W,X(N,W));
// rep(k,W) rep(i,N){
// val[k][i][i] = X[i][k];
// rep(j,i+1,N) val[k][i][j] = min(val[k][i][j-1], X[j][k]);
// }
// rep(i,N) dp[i][i] = sum[k,0,W](val[k][i][i]);
// rrep(i,N) rep(j,i+1,N){
// s = sum[k,0,W](val[k][i][j]);
// dp[i][j] = min[k,i,j](dp[i][k]+dp[k+1][j]-s);
// }
// wt(2*dp[0][N-1]);
// }