## Problem 3: Smallest Latin Square

A square arrangment of numbers such as

```1 2 3 4 5
2 1 4 5 3
3 4 5 1 2
4 5 2 3 1
5 3 1 2 4```

is a Latin Square because each whole number 1, 2, 3, 4 and 5 appears exactly once in each row and column of the square.

Of all the possible 5x5 Latin squares, the one above is the smallest in the following sense: if the digits are strung together (in rows from top to bottom) the resulting integer,

12345 21453 34512 45231 53124

is the smallest one possible.

### Input

On the first line is M, an integer indicating the number of test cases.
On each of the next M lines is an integer N between 2 and 9.

### Output

Output the smallest NxN latin square for each test case.

```1
5
```

### Sample Output

```1 2 3 4 5
2 1 4 5 3
3 4 5 1 2
4 5 2 3 1
5 3 1 2 4
```

Point Value: 10
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 29, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

## Comments (Search)

• (1/1)
how do u use it?

• (0/5)
that's for you to figure out.

• (8/1)
and you too apparently.

• (0/1)
I'm guessing you're not allowed to hardcode each individual
square?

• (1/0)
more of a challenge.

• (1/0)
Unless he does know recursion, but his solution is very inefficient and takes over 2 seconds. Then he could simply let it run for a minute, hard code it, and he's done. So it's a fair question.

• (0/0)
It's funny because Brian hard-coded them. ;)

• (0/0)
I think for me it was more of a challenge to hard-code, because I found the solutions by hand.