#K60827. Spiral Matrix Generator
Spiral Matrix Generator
Spiral Matrix Generator
You are given a positive integer N. Your task is to generate an N × N spiral matrix filled with integers from 1 to N2 in clockwise order. The spiral starts at the top-left corner and moves to the right initially.
For example, when N = 3 the spiral matrix is:
[ \begin{matrix} 1 & 2 & 3 \ 8 & 9 & 4 \ 7 & 6 & 5 \end{matrix} ]
After generating the spiral matrix, print it with each row on a new line and an empty line after each test case.
inputFormat
The input is provided via standard input and is formatted as follows:
- The first line contains an integer T (the number of test cases).
- Each of the following T lines contains a single integer N (1 ≤ N ≤ 100), representing the size of the matrix.
outputFormat
For each test case, output the corresponding N × N spiral matrix. Each row of the matrix should be printed on a separate line with its elements separated by a single space. After each test case, print an extra blank line.
Note: The output should be written to standard output.
## sample1
3
1 2 3
8 9 4
7 6 5
</p>