Boxes

No attempts yetTime limit1sMemory limit256 MB

Problem

You are given a grid with mm rows and nn columns. Some cells hold a box. If every box moves down until it can move no further, the boxes end up stacked on the floor. Boxes cannot pass through each other, so a column holding kk boxes ends up with its bottom kk cells filled.

The distance a box moves is the number of cells it travels down from its starting cell to its final cell. The 5 by 4 grid in the first example holds 7 boxes, and the topmost box of the leftmost column moves down 2 cells. The 7 boxes in that grid move a total distance of 8.

Write a program that computes the total distance moved by all boxes, meaning the sum of the distances moved by each box.

Input

The first line has the number of test cases TT.

The first line of each test case has mm and nn (1m,n1001 \le m, n \le 100). The next mm lines each have nn integers describing one row of the grid, given from the first row to the last row. A cell holding a box is 1 and an empty cell is 0, with one space between integers.

Output

For each test case, print the total distance moved by all boxes on one line.