Codeforces Global Round 28
E
Kevin and Bipartite Graph
Codeforces
2000
原题
← DF →
翻译中…

The Arms Factory needs a poster design pattern and finds Kevin for help.

翻译中…

A poster design pattern is a bipartite graph with $ 2n $ vertices in the left part and $ m $ vertices in the right part, where there is an edge between each vertex in the left part and each vertex in the right part, resulting in a total of $ 2nm $ edges.

翻译中…

Kevin must color each edge with a positive integer in the range $ [1, n] $. A poster design pattern is good if there are no monochromatic cycles$^{\text{∗}}$ in the bipartite graph.

翻译中…

Kevin needs your assistance in constructing a good bipartite graph or informing him if it is impossible.

翻译中…

$^{\text{∗}}$A monochromatic cycle refers to a simple cycle in which all the edges are colored with the same color.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $ t $ ($ 1 \le t \le 100 $).

翻译中…

The only line of each test case contains two integers $ n $ and $ m $ ($ 1 \le n, m \leq 10^3 $) — the bipartite graph has $ 2n $ vertices in the left part and $ m $ vertices in the right part.

翻译中…

It is guaranteed that both the sum of $ n $ and the sum of $ m $ over all test cases do not exceed $ 10^3 $.

翻译中…

Output

翻译中…

For each test case, if there is no solution, then output No.

翻译中…

Otherwise, output Yes, and then output $ 2n $ lines, with each line containing $ m $ positive integers. The $ i $-th line's $ j $-th integer represents the color of the edge between the $ i $-th vertex in the left part and the $ j $-th vertex in the right part.

翻译中…

If there are multiple answers, you can print any of them.

翻译中…

You can output each letter in any case (for example, the strings yEs, yes, Yes, and YES will be recognized as a positive answer).

翻译中…

Note

翻译中…

For the first test case, the graph is shown as follows:

翻译中…

image

翻译中…

For the second test case, it can be proven that there is no valid solution.

翻译中…

样例

Input #1
3
2 2
3 7
5 4
Output #1
YES
1 2
2 1
2 2
2 1
NO
YES
1 1 1 1
1 2 2 2
1 2 3 3
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
InputCopy OutputCopy
题目信息
题号
2048E
时间限制
2 s
内存限制
256 MB
标签
构造
图论
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。