Gardening

Time limit: 0.2s Memory limit: 512MB Input: Output:

Azusa, the witch of the highlands, wants to do a fun activity with her friend Laika: gardening. They want to make a rectangular garden NN meters tall by MM meters wide. The garden is divided into 11 meter by 11 meter squares. The question is: what flowers should they plant?

Laika has found KK different types of flowers. Azusa and Laika will plant one type of flower in each 11 meter by 11 meter square. Furthermore, for aesthetic reasons, the garden must satisfy the following constraints:

  1. Each flower type must appear at least once in the garden.
  2. For any two squares where the same flower type is planted, a path between them where all the intermediate squares have the same type of flower must exist. For example, the following gardens are not allowed:

  1. Any square must have exactly two adjacent squares planted with the same type of flower. For example, the following gardens are not allowed:

Note that, in the previous constraints, two squares are “adjacent” if and only if they share a common edge (not merely a corner); and a path is a sequence of adjacent squares.

You are given TT different values for N,MN, M and KK. Help Azusa and Laika create gardens that satisfy the conditions for each test case — or, tell them that it is impossible to do this.

Input data

The first line of the input contains the integer TT. Afterwards, TT lines follow, each describing a test case. Each test case consists of three integers N,MN, M and KK.

Output data

Output the answers for each test case in order. For a test case, if no solution exists, output NO on a single line. Otherwise, first output YES on a single line, and then output NMN \cdot M integers arranged in NN lines and MM columns describing the required garden. The lines and columns of the output correspond to the lines and columns of the garden, with each integer corresponding to a 11 meter by 11 meter square. The integers represent the types of flowers planted in the squares, where the types are indexed from 11 to KK. If there are multiple correct solutions you may output any of them.

Restrictions

  • 1T100 0001 \leq T \leq 100 \ 000
  • 1N,M200 0001 \leq N, M \leq 200 \ 000
  • 1KNM1 \leq K \leq N \cdot M
  • Let SS equal the sum of NMN \cdot M for all the test cases in a file for which an answer exists (i.e. where the output is not NO).
  • S200 000S \leq 200 \ 000
# Points Restrictions
1 5 N,M4N, M \leq 4
2 6 N4N \leq 4
3 10 N10N \leq 10
4 18 N=18N = 18
5 39 KK is chosen uniformly at random between 1 and NMN \cdot M
6 22 No further restrictions.

Examples

stdin

5
2 2 2
2 2 1
4 4 4
4 4 2
4 6 3

stdout

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

Explanations

For the first test case, we note that no 22 by 22 garden with 22 types of flowers is possible. Thus we output NO. The other gardens are pictured below:

Log in or sign up to be able to send submissions!