Problem: Irving & Cohen Petroleum Corporation has decided to develop a new oil field in an area. A preliminary survey has been done and they created a detailed grid map of the area which indicates the reserve of oil.

They are now planning to construct mining plants on several grid blocks according this map, but they decided not to place any two plants on adjacent positions to avoid spreading of fire in case of blaze. Two blocks are considered to be adjacent when they have a common edge. You are one of the programmers working for the company and your task is to write a program which calculates the maximum amount of oil they can mine, given the map of the reserve.



Input

The first line of the input specifies N, the number of test cases. Then N test cases follow, each of which looks like the following:


W H
r1,1 r2,1 . . . rW,1
...
r1,H r2,H . . . rW,H


The first line of a test case contains two integers W and H (1 ≤ W, H ≤ 20). They specifies the dimension of the area. The next H lines, each of which contains W integers, represent the map of the area. Each integer rx,y (0 ≤ rx,y < 10000) indicates the oil reserve at the grid block (x, y).

Output

For each test case, output the case number (starting from 1) and the maximum possible amount of mining in a line. Refer to the sample output section about the format.

Example

Input

2
2 2
2 3
3 5
3 2
4 1 1
2 1 4


Output

Case 1: 7
Case 2: 8

Solution (in CPP):

Solution:
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;

const int D_MAX_V = 1010;
const int D_v_size = 1010;
struct D_wolf {
	int t, c, r;
	D_wolf() { t = c = r = 0; }
	D_wolf(int t1, int c1, int r1) {
		t = t1; c = c1; r = r1;
	}
};
vector<D_wolf>D_G[D_MAX_V];
int D_level[D_MAX_V];
int D_iter[D_MAX_V];

void add_edge(int from, int to, int cap) {
	D_G[from].push_back(D_wolf(to, cap, D_G[to].size()));
	D_G[to].push_back(D_wolf(from, 0, D_G[from].size() - 1));
}
void D_bfs(int s) {
	for(int i = 0; i < D_v_size; i++)D_level[i] = -1;
	queue<int> Q;
	D_level[s] = 0;
	Q.push(s);
	while(Q.size()) {
		int v = Q.front();
		Q.pop();
		for(int i = 0; i < D_G[v].size(); i++) {
			if(D_G[v][i].c>0 && D_level[D_G[v][i].t] < 0) {
				D_level[D_G[v][i].t] = D_level[v] + 1;
				Q.push(D_G[v][i].t);
			}
		}
	}
}
int D_dfs(int v, int t, int f) {
	if(v == t)return f;
	for(; D_iter[v] < D_G[v].size(); D_iter[v]++) {
		int i = D_iter[v];
		if(D_G[v][i].c>0 && D_level[v] < D_level[D_G[v][i].t]) {
			int d = D_dfs(D_G[v][i].t, t, min(f, D_G[v][i].c));
			if(d > 0) {
				D_G[v][i].c -= d;
				D_G[D_G[v][i].t][D_G[v][i].r].c += d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s, int t) {
	int flow = 0;
	for(;;) {
		D_bfs(s);
		if(D_level[t] < 0)return flow;
		for(int i = 0; i < D_v_size; i++)D_iter[i] = 0;
		int f;
		while((f = D_dfs(s, t, 99999999))>0) { flow += f; }
	}
	return 0;
}
int W, H;
int toV(int i, int j) {
	return W * i + j;
}

int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int Test;
	cin >> Test;
	for(int t = 1; t <= Test; t++) {
		cin >> W >> H;
		int r[20][20];
		int sum = 0;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				cin >> r[i][j];
				sum += r[i][j];
			}
		}

		for(int i = 0; i < H * W + 2; i++) {
			D_G[i].clear();
			D_level[i] = D_iter[i] = 0;
		}

		int S = H * W, T = S + 1;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if((i + j) % 2 == 0) {
					add_edge(S, toV(i, j), r[i][j]);
					add_edge(toV(i, j), T, 0);
					for(int k = 0; k < 4; k++) {
						int ni = i + dy[k], nj = j + dx[k];
						if(ni < 0 || H <= ni || nj < 0 || W <= nj) continue;
						add_edge(toV(i, j), toV(ni, nj), 1e9);
					}
				}
				else {
					add_edge(S, toV(i, j), 0);
					add_edge(toV(i, j), T, r[i][j]);
				}
			}
		}

		cout << "Case " << t << ": " << sum - max_flow(S, T) << endl;
	}

}