DreamLand and Lazy people

3

1 votes
Easy
Problem

A long time ago, in a galaxy far, far away...

There was a Dreamland with lazy people. They had a perfectly shaped land to farm. The land was perfectly plane without any ups or downs and was also equally fertile throughoutly.

The land was perfectly rectangular. But the distribution of land between people was terrible and this was a subject of debate when it was time to water the plants. As mentioned people were lazy and so wanted to reduce their work.

If the water is started in one block, it also moves to all the adjacent blocks.

So they decided to re-distribute the land in such a way that work must be reduced as much as possible, so they don't have to go on multiple places(blocks) for watering the plants but in doing so others should not get benefit from ones work(water from our farm should not go to others farm).

The second part can be solved by having compound around the farm so water will remain in ones field only. But as they are lazy they are in need for solving the first problem and is been asked to you.

Can you help them?

INPUT

First line of input contains a number T denoting number of test cases.

For each test case first line will have numbers N,M denoting size of field

and P denoting number of people

The second line will contain P numbers, where ith number denotes the area of the farm that ith person owns.Note: Every block of land is owned by some farmer.

OUTPUT

Distribute the land in such a way to reduce efforts as mentioned above.

You have to output the complete area with each square distributed to whom.
Formally, you have to print N lines with M space separated integers, where each integer denotes the farmer id, so it should be between 1 and P, both inclusive.
Refer sample test cases for more clarity.

As there may be many ways to do so, print any one to pass the tests.

CONSTRAINTS

1<=T<=10;
1<=N,M,P<=50
0<=Pi<=N*M

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?