Bob has a table with rows and
columns, and he wants to fill each cell with an integer from
to
, following a few special rules.
Each cell must contain exactly one integer from to
, and the table must satisfy all of the following constraints:
Every number from
to
must appear at least once in the table.
Each cell must have exactly two adjacent cells (up, down, left, or right) that contain the same number.
All cells with the same number must form a connected region — that is, if two cells contain the same number, there must be a path between them using only cells with that number, moving only up, down, left, or right.
Given ,
, and
, can you help Bob fill the table while satisfying these constraints? If it's not possible, just output
NO
.
Input Specification
The first line contains an integer (
), the number of test cases.
Each of the following lines contains three integers
,
,
, (
,
), — the number of rows, columns, and number range. The sum of
for all test cases is not more than
.
Output Specification
For each test case, if it is impossible to create a valid garden, print NO
. Otherwise, print YES
and then a valid solution to fill up the table. Each integer is from to
. If there are multiple ways, you may print any valid solution.
Note that the checker for this problem is custom and, hence, the whitespace is strict, so do not output excess whitespace.
Constraints
Subtask | Points | Additional constraints |
---|---|---|
No additional constraints |
Sample Input
5
2 2 2
2 2 1
4 4 4
4 4 2
4 6 3
Sample Output
NO
YES
1 1
1 1
YES
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4
YES
1 1 1 1
1 2 2 1
1 2 2 1
1 1 1 1
YES
1 1 1 1 1 1
1 2 2 3 3 1
1 2 2 3 3 1
1 1 1 1 1 1
Comments