a947: Yet Another Card Problem
Tags :
Accepted rate : 2人/8人 ( 25% ) [非即時]
評分方式:
Special

最近更新 : 2023-02-27 18:34

Content

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.

Input

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$.

Output

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.

Sample Input #1
1
3 1
Sample Output #1
1 4 5
2 3 6
9 8 7
測資資訊:
記憶體限制: 128 MB
不公開 測資點#0 (10%): 1.0s , <1K
不公開 測資點#1 (10%): 1.0s , <1K
不公開 測資點#2 (10%): 1.0s , <1K
不公開 測資點#3 (10%): 1.0s , <1K
不公開 測資點#4 (10%): 1.0s , <1K
不公開 測資點#5 (10%): 2.0s , <1K
不公開 測資點#6 (10%): 2.0s , <1K
不公開 測資點#7 (10%): 2.0s , <1K
不公開 測資點#8 (10%): 2.0s , <1K
不公開 測資點#9 (10%): 2.0s , <1K
Hint :
Tags:
出處:
[管理者: ]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」