Problem: For a square matrix of integers of size , let's define its beauty as follows: for each pair of side-adjacent elements and , write out the number , and then find the number of different numbers among them.
For example, for the matrix the numbers we consider are , , and ; there are different numbers among them (, and ), which means that its beauty is equal to .
You are given an integer . You have to find a matrix of size , where each integer from to occurs exactly once, such that its beauty is the maximum possible among all such matrices.
Input Format: The first line contains a single integer () – the number of test cases.
The first (and only) line of each test case contains a single integer ().
Output Format: For each test case, print rows of integers — a matrix of integers of size , where each number from to occurs exactly once, such that its beauty is the maximum possible among all such matrices. If there are multiple answers, print any of them.