CF1783B.Matrix of Differences
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For a square matrix of integers of size n×n , let's define its beauty as follows: for each pair of side-adjacent elements x and y , write out the number ∣x−y∣ , and then find the number of different numbers among them.
For example, for the matrix (1432) the numbers we consider are ∣1−3∣=2 , ∣1−4∣=3 , ∣3−2∣=1 and ∣4−2∣=2 ; there are 3 different numbers among them ( 2 , 3 and 1 ), which means that its beauty is equal to 3 .
You are given an integer n . You have to find a matrix of size n×n , where each integer from 1 to n2 occurs exactly once, such that its beauty is the maximum possible among all such matrices.
输入格式
The first line contains a single integer t ( 1≤t≤49 ) – the number of test cases.
The first (and only) line of each test case contains a single integer n ( 2≤n≤50 ).
输出格式
For each test case, print n rows of n integers — a matrix of integers of size n×n , where each number from 1 to n2 occurs exactly once, such that its beauty is the maximum possible among all such matrices. If there are multiple answers, print any of them.
输入输出样例
输入#1
2 2 3
输出#1
1 3 4 2 1 3 4 9 2 7 5 8 6