# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

# Matrix Construction

By Arghya · Limits 1s, 512 MB · Custom Checker

Construct a square matrix $a$ of size $n×n$ satisfying the following conditions,

1. Each row of the matrix is a permutation of size $n$
2. Each column of the matrix is a permutation of size $n$
3. The matrix is symmetric, that means $a[i][j] = a[j][i]$ for all possible $i,j$ $(1≤i,j≤n)$
4. The matrix satisfies $a[i][i] = i$ for all $i$ $(1≤i≤n)$

If it is possible to build such a matrix, print the matrix otherwise print $-1$.

## Input

First line of input consists of a single integer $T$, the number of test cases $(1 ≤ T ≤ 5)$
Each test case consists of one line. First and only line of the test case contains $n$, the dimension of the matrix. $(1 ≤ n ≤ 1000)$.

## Output

Print the matrix if possible, otherwise print $-1$. If there are multiple possible answers, anyone would be acceptable.

## Sample

InputOutput
2
2
3

-1
1 3 2
3 2 1
2 1 3


We call a sequence of integers $A$ permutation if every integer from 1 to |A| appears exactly once in the sequence, where $|A|$ denotes the length of the sequence.

### Statistics

100% Solution Ratio

Tahmid690Earliest, 1d ago

Tahmid690Fastest, 0.2s

Tahmid690Lightest, 16 MB

Tahmid690Shortest, 963B

### Submit

Login to submit

### Related Contests

 BRACU জয়যাত্রা’50 Techfest Inter University Individual Programming ContestEnded 3w ago