#K50032. 90° Matrix Rotation

    ID: 28774 Type: Default 1000ms 256MiB

90° Matrix Rotation

90° Matrix Rotation

You are given a square matrix of size \(N \times N\). Your task is to rotate the matrix by 90° clockwise. The rotation should be performed on each of the test cases provided.

Input Format:
The input starts with an integer \(T\), the number of test cases. For each test case, the first line contains an integer \(N\), the dimension of the matrix. This is followed by \(N\) lines, each containing \(N\) integers separated by spaces representing the matrix rows.

Output Format:
For each test case, output the rotated matrix. Each row of the rotated matrix should be printed on a new line with the elements separated by a space.

Example:

Input:
1
3
1 2 3
4 5 6
7 8 9

Output:
7 4 1
8 5 2
9 6 3

inputFormat

The first line contains an integer \(T\) representing the number of test cases. Each test case begins with an integer \(N\) indicating the size of the matrix. The next \(N\) lines for each test case contain \(N\) space-separated integers representing the rows of the matrix.

For example:

3
3
1 2 3
4 5 6
7 8 9
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
1
42

outputFormat

For each test case, output the rotated matrix which is the original matrix rotated 90° clockwise. Each row of the matrix should be printed on its own line with values separated by a single space.

Corresponding to the above input, the output will be:

7 4 1
8 5 2
9 6 3
13 9 5 1
14 10 6 2
15 11 7 3
16 12 8 4
42
## sample
3
3
1 2 3
4 5 6
7 8 9
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
1
42
7 4 1

8 5 2 9 6 3 13 9 5 1 14 10 6 2 15 11 7 3 16 12 8 4 42

</p>