SP212 WATER - Water among Cubes

Description

On a rectangular mesh comprising _n\*m_ fields, _n\*m_ cuboids were put, one cuboid on each field. A base of each cuboid covers one field and its surface equals to one square inch. Cuboids on adjacent fields adhere one to another so close that there are no gaps between them. A heavy rain pelted on a construction so that in some areas puddles of water appeared. ### Task Write a program which: - reads from the standard input a size of the chessboard and heights of cuboids put on the fields, - computes maximal water volume, which may gather in puddles after the rain, - writes results in the standard output.

Input Format

The number of test cases t is in the first line of input, then t test cases follow separated by an empty line. In the first line of each test case two positive integers 1

Output Format

Your program should write for each tes case one integer equal to the maximal volume of water (given in cubic inches), which may gather in puddles on the construction.