#K34417. Matrix Rotation: 90° Clockwise

    ID: 25305 Type: Default 1000ms 256MiB

Matrix Rotation: 90° Clockwise

Matrix Rotation: 90° Clockwise

You are given one or more square matrices. Your task is to rotate each matrix by \(90^\circ\) clockwise.

For example, given the matrix:

1 2 3
4 5 6
7 8 9

After a \(90^\circ\) clockwise rotation, it becomes:

7 4 1
8 5 2
9 6 3

You need to process multiple test cases. All input is read from standard input (stdin) and the output must be printed on standard output (stdout).

inputFormat

The first line contains an integer \(T\) — the number of test cases. Each test case starts with an integer \(N\) specifying the size of the \(N \times N\) square matrix, followed by \(N^2\) integers denoting the elements of the matrix in row-major order. Input elements are separated by spaces.

T
N a11 a12 ... a1N a21 ... aNN
...

outputFormat

For each test case, output a single line containing the rotated matrix's elements in row-major order, with each element separated by a single space.

rotated_matrix_line_1
rotated_matrix_line_2
...
## sample
2
3 1 2 3 4 5 6 7 8 9
2 1 2 3 4
7 4 1 8 5 2 9 6 3

3 1 4 2

</p>