409899: GYM103828 L No Arithmetic subsequence

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

L. No Arithmetic subsequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Construct an $$$n \times n$$$ grid with numbers from $$$1$$$ to $$$n \times n$$$ (each number exists exactly once) such that there is no row nor column that contains a subsequence (has exactly more than $$$2$$$ elements) which forms an Arithmetic Progression.

Arithmetic Progression is a sequence of numbers in order, in which the difference between any two consecutive numbers is a constant value.

Input

The first line of input contains a single integer $$$T$$$, the number of test cases.

The next $$$T$$$ lines each contains a single integer $$$n$$$ $$$(3 \le n \le 500)$$$, the dimension of the grid.

The sum of $$$n$$$ over all test cases doesn't exceed $$$500$$$

Output

For each test case with input $$$n$$$ print n lines each having n integers describing the required grid. It is guaranteed that there is always one solution at least. If there are multiple answers print any of them.

ExampleInput
1
3
Output
1 3 2 
7 9 8 
4 6 5 

加入题单

上一题 下一题 算法标签: