QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 512 MB 总分: 100 可 Hack ✓

#9582. Russian-style Light Meal

统计

We have the following two types of tetrominoes:

Figure 1: Available tetromino types

Both types of tetrominoes can be used an unlimited number of times and can be flipped, mirrored, or rotated by $90^\circ/180^\circ/270^\circ$.

Construct a tiling of an $n \times m$ grid that covers the grid without overlaps or gaps, or report that no such tiling exists.

For example, the figure below shows one valid tiling for a $6 \times 8$ grid:

Figure 2: A valid tiling

Input

The input may contain multiple test cases. The first line contains the number of test cases $T$ ($1 \le T \le 10^5$).

For each test case, a single line contains two integers $n$ and $m$ ($n \times m \le 10^5, n, m \ge 1$), representing the number of rows and columns of the grid.

The sum of $n \times m$ over all test cases does not exceed $2 \times 10^5$.

Output

For each test case:

First, output "YES" or "NO" (case-sensitive) to indicate whether a solution exists.

If a solution exists, output $n$ lines, each containing $m$ integers, describing the tiling. Each tetromino is assigned a unique positive integer ID starting from 1. The ID must appear exactly 4 times in the $n \times m$ grid to identify the position of that tetromino. You are not allowed to skip IDs; that is, before using an ID $k$ ($k > 1$), you must have already used IDs $1, 2, \dots, k-1$.

If there are multiple valid tilings, you may output any one of them.

Examples

Input 1

3
2 3
2 4
6 8

Output 1

NO
YES
1 1 1 1
2 2 2 2
YES
1 1 1 2 11 11 11 11
1 4 5 2 2 2 12 12
8 4 5 5 5 6 12 10
8 4 4 6 6 6 12 10
8 8 9 9 9 9 7 10
3 3 3 3 7 7 7 10

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.