| “壹零杯”第三届西华师范大学程序设计竞赛 |
|---|
| Finished |
Deep within the ruins, you need to reconstruct a square energy matrix of size $$$n \times n$$$.
You have exactly $$$n^2$$$ energy crystals, with energy levels ranging from 1 to $$$n^2$$$. You must place all $$$n^2$$$ crystals into the matrix, such that each cell contains exactly one crystal.
To prevent dangerous resonance explosions between the crystals, an ancient rule states: The absolute difference in energy levels between any two adjacent crystals (sharing an edge, either horizontally or vertically) must be strictly greater than 1.
Formally, for any two adjacent elements $$$x$$$ and $$$y$$$ in the matrix, $$$|x - y| \gt 1$$$ must hold.
Please construct a valid placement for the matrix. If no such placement exists, output -1.
The first line contains a single integer $$$t$$$ (1 $$$\le t \le$$$ 100) — the number of test cases.
For each test case, the only line contains a single integer $$$n$$$ (1 $$$\le n \le$$$ 100) — the size of the matrix.
For each test case:
3123
1 -1 1 8 6 4 2 9 7 5 3
| Name |
|---|


