#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<climits>
#include<cassert>
#include<bitset>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX (1<<20)

using namespace std;

typedef long long ll;

ll dp[MAX][2],ans;
int N,H,W,r[20][20],CNT=1;

int main(){
  cin >> N;
  while(N--){
    ans = 0;
    cin >> W >> H;
    rep(i,H)rep(j,W)cin >> r[i][j];
    rep(i,MAX)rep(j,2)dp[i][j] = 0;
    rep(i,(1<<W)){
      ll cost = 0;
      bool out = false;
      rep(j,W){
	if( ( (i>>j)&1 ) && ( j-1>=0 && ((i>>(j-1))&1) ) ){
	  out = true;
	  break;
	}
	if( (i>>j)&1 )cost += r[0][j];
      }
      if(out)continue;
      dp[i][0] = cost;
      ans = max(ans,cost);
    }
    int bitmask = (1<<W)-1;
    bool phase = 0;
    REP(y,1,H){
      rep(x,W){
	rep(state,(1<<W)){
	  // not use
	  int nstate = (state>>1)&bitmask;
	  dp[nstate][!phase] = max(dp[nstate][!phase],dp[state][phase]);
	  ans = max(ans,dp[nstate][!phase]);

	  // use y                      x
	  if( (state&1) || ( ( (state>>(W-1))&1 ) && x-1>=0  ) )continue;
	  nstate |= (1<<(W-1));
	  dp[nstate][!phase] = max(dp[nstate][!phase],dp[state][phase]+r[y][x]);
	  ans = max(ans,dp[nstate][!phase]);
	}
	rep(i,(1<<W))dp[i][phase] = 0;
	phase = !phase;
      }
    }

    cout << "Case " << CNT++ << ": " << ans << endl;
  }

  return 0;
}