﻿ Fuzhou University OnlineJudge ﻿
Problem 2143 Board Game

## Problem Description

Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of the board which is own by Fat brother is consisting of an integer 0. At each turn, he can choose two adjacent grids and add both the integer inside them by 1. But due to some unknown reason, the number of each grid can not be large than a given integer K. Also, Maze has already drown an N*M board with N*M integers inside each grid. What Fat brother would like to do is adding his board to be as same as Maze’s. Now we define the different value of two boards A and B as:

Now your task is to help Fat brother the minimal value of S he can get.

## Input

The first line of the date is an integer T, which is the number of the text cases.

Then T cases follow, each case contains three integers N, M and K which are mention above. Then N lines with M integers describe the board.

1 <= T <= 100, 1 <= N, M, K <= 9

0 <= the integers in the given board <= 9

## Output

For each case, output the case number first, then output the minimal value of S Fat brother can get.

## Sample Input

5 2 2 9 3 4 2 3 1 3 9 4 6 4 1 1 9 9 3 3 5 1 2 3 4 5 6 7 8 9 3 3 9 1 2 3 4 5 6 7 8 9

## Sample Output

Case 1: 0 Case 2: 2 Case 3: 81 Case 4: 33 Case 5: 5

Submit  Back  Status  Discuss
﻿