Alice likes playing a game on an N x M board where each cell contains some points. Rows are numbered from 1 to N from top to bottom, and columns are numbered from 1 to M from left to right. She starts from the (1, 1) cell and ends her journey on the (N, M) cell. But on each move, she can only move in the right or down cell. When she is in a cell, she collects all the points in that cell. Alice loves points a lot. So she always moves in a way that the total number of points she can collect is maximized.
Bob has an empty N x M board which is placed vertically. He also has N x M number of (1 x 1) blocks and each block has some points. The blocks fall from above the board one by one and he can decide which block falls into which columns. A block falls as long as it does not hit another block or if it hits the bottom of the board. He also does not make a block fall into a full column (a column that already has N blocks).
Bob fills the empty board with all blocks in the above-mentioned manner and then gives the filled board to Alice. He wants to make Alice happy as much as possible. So he fills the empty board with the blocks so that Alice can get the maximum number of points.
Can you find out how Bob will fill the board and how many points Alice will get?
Input
The first line will contain a single integer T (1 ≤ T ≤ 106) denoting the number of test cases. In each test case, the first line will have two space-separated integers N, M (1 ≤ N x M ≤ 105) denoting the number of rows and columns respectively. In the second line, there will be N x M space-separated integers P1, P2, ..., PNxM (0 ≤ Pi ≤ 109) denoting the points of the blocks.The blocks fall in the order given in the input.
The sum of N x M over all test cases does not exceed 106.
Output
For each test case, in the first line, print the maximum number of points Alice will get. In the second line, print N x M space-separated integers, C1, C2, ..., CNxM (1 ≤ Ci ≤ M) where Ci denotes the column Bob chooses for the ith block to fall. Please see the sample for details.
Note that, there might be multiple optimal ways of falling the blocks. You can output any valid optimal solution.
Sample
Sample Input | Sample Output |
---|---|
2 2 2 4 5 5 4 2 1 10 9 | 14 2 1 1 2 19 1 1 |
Notes
For the 1st sample test, initially 2X2 board is placed vertically. Blocks will fall into it one by one maintaining the given input order. An example of filling the board with blocks so that Alice can maximize her points is shown below.
One possible optimal path visited by Alice is shown below (visited cells in bold).
So the maximum number of points obtained by Alice = 5 + 5 + 4 = 14.