3028: Boxes

时间限制:4000 ms 内存限制:128 MB
上传者:
提交:2 通过:2

题目描述

OldWC is a warehouseman, the warehouse can be described as a $n \times m$ grid, there are several(maybe none) boxes on each grid.In order to prevent dumping, on each grid, boxes can not be stacked for more than $h$ layers.OldWC needs to move some boxes to meet the requirement, every time, he can move a box from one grid to an adjacent grid,two grids are adjacent if and only if they share an edge.

Calculate how many times he needs to move at least to make each pile of boxes within $h$ layers.

输入格式

The first line contains an integer number T, the number of test cases.

For each test case :
The first line contains three integers $n$, $m$, $h$($1 \leq n , m, h \leq 50$), the size of the warehouse and the limited number of layers.

The following $n$ lines, each contains $m$ integers $a_{ij}$($0 \leq a_{ij} \leq 50$), the initial number of boxes on the $i^{th}$ row $j^{th}$ column.

It's guaranteed that $\sum a_{ij} \leq n \times m \times h$.

输出格式

For each test case print the answer.

输入样例 复制

1
2 3 5
1 2 9
6 5 4

输出样例 复制

5