{"trustable":true,"prependHtml":"\u003cscript\u003e\n window.katexOptions \u003d {\n delimiters: [\n {left: \u0027\\\\(\u0027, right: \u0027\\\\)\u0027, display: false},\n ]\n };\n\u003c/script\u003e\n","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eDreamGrid, the king of Gridland, is making a knight tournament. There are $n$ knights, numbered from 1 to $n$, participating in the tournament. The rules of the tournament are listed as follows:\u003c/p\u003e\r\n\r\n\u003cul\u003e\r\n \u003cli\u003eThe tournament consists of $k$ rounds. Each round consists of several duels. Each duel happens between exactly two knights.\u003c/li\u003e\r\n \u003cli\u003eEach knight must participate in exactly one duel during each round.\u003c/li\u003e\r\n \u003cli\u003eFor each pair of knights, there can be at most one duel between them during all the $k$ rounds.\u003c/li\u003e\r\n \u003cli\u003eLet $1 \\le i, j \\le k$, $i \\ne j$, and $1 \\le a, b, c, d \\le n$, $a, b, c, d$ be four distinct integers. If\r\n \u003cul\u003e\r\n \u003cli\u003eKnight $a$ fights against knight $b$ during round $i$, and\u003c/li\u003e\r\n \u003cli\u003eKnight $c$ fights against knight $d$ during round $i$, and\u003c/li\u003e\r\n \u003cli\u003eKnight $a$ fights against knight $c$ during round $j$,\u003c/li\u003e\r\n \u003c/ul\u003e\r\n then knight $b$ must fight against knight $d$ during round $j$.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\r\n\u003cp\u003eAs DreamGrid\u0027s general, you are asked to write a program to arrange all the duels in all the $k$ rounds, so that the resulting arrangement satisfies the rules above. \u003c/p\u003e\r\n\r\n\u003ch4\u003eInput\u003c/h4\u003e\r\n\u003cp\u003eThere are multiple test cases. The first line of the input is an integer $T$, indicating the number of test cases. For each test case:\u003c/p\u003e\r\n\r\n\u003cp\u003eThe first and only line contains two integers $n$ and $k$ ($1 \\le n, k \\le 1000$), indicating the number of knights participating in the tournament and the number of rounds.\u003c/p\u003e\r\n\r\n\u003cp\u003eIt\u0027s guaranteed that neither the sum of $n$ nor the sum of $k$ in all test cases will exceed 5000.\u003c/p\u003e\r\n\r\n\u003ch4\u003eOutput\u003c/h4\u003e\r\n\u003cp\u003eFor each test case:\u003c/p\u003e\r\n\r\n\u003cul\u003e\r\n \u003cli\u003e\r\n \u003cp\u003eIf it\u0027s possible to make a valid arrangement, output $k$ lines. On the $i$-th line, output $n$ integers $c_{i, 1}, c_{i, 2}, \\dots, c_{i, n}$ separated by one space, indicating that in the $i$-th round, knight $j$ will fight against knight $c_{i, j}$ for all $1 \\le j \\le n$.\u003c/p\u003e\r\n \u003cp\u003eIf there are multiple valid answers, output the lexicographically smallest answer.\u003c/p\u003e\r\n \u003cp\u003eConsider two answers $A$ and $B$, let\u0027s denote $a_{i, j}$ as the $j$-th integer on the $i$-th line in answer $A$, and $b_{i, j}$ as the $j$-th integer on the $i$-th line in answer $B$. Answer $A$ is lexicographically smaller than answer $B$, if there exists two integers $p$ ($1 \\le p \\le k$) and $q$ ($1 \\le q \\le n$), such that\r\n \u003c/p\u003e\u003cul\u003e\r\n \u003cli\u003efor all $1 \\le i \u0026lt; p$ and $1 \\le j \\le n$, $a_{i, j} \u003d b_{i, j}$, and\u003c/li\u003e\r\n \u003cli\u003efor all $1 \\le j \u0026lt; q$, $a_{p, j} \u003d b_{p, j}$, and finally $a_{p, q} \u0026lt; b_{p, q}$.\u003c/li\u003e\r\n \u003c/ul\u003e\r\n \u003cp\u003e\u003c/p\u003e\r\n \u003c/li\u003e\r\n\r\n \u003cli\u003eIf it\u0027s impossible to make a valid arrangement, output \"Impossible\" (without quotes) in one line.\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\r\n\u003cp\u003ePlease, DO NOT output extra spaces at the end of each line, or your answer may be considered incorrect!\u003c/p\u003e\r\n\r\n\u003ch4\u003eSample\u003c/h4\u003e\n\u003ctable class\u003d\"vjudge_sample\"\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n3 1\r\n4 3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eImpossible\r\n2 1 4 3\r\n3 4 1 2\r\n4 3 2 1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n\r\n"}}]}