Juju has $n^2$ cards numbered from $1$ to $n^2$.
Juju loves the number $k$ so much. He wants to arrange these cards into a $n \times n$ matrix, such that the number of adjacent pairs of cards $(a, b)$ which satisfies $abs(a - b) = k$ is maximum. Note that two cells in the matrix are considered adjacent if and only if they share an edge.
Find one such matrix.
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \leq t \leq 50$). The description of the test cases follows.
The only line of a test case contains two integers $n$ and $k$ ($1 \leq k < n$).
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^3$.
For each test case, output a $n \times n$ matrix with the maximum number of adjacent pairs $(a, b)$ which satisfies $abs(a - b) = k$.
If there are serveral answers, please print any of them.
1 3 1
1 4 5 2 3 6 9 8 7
ID | User | Problem | Subject | Hit | Post Date |
沒有發現任何「解題報告」 |