#C5656. Matrix Rotation: 90-Degree Clockwise
Matrix Rotation: 90-Degree Clockwise
Matrix Rotation: 90-Degree Clockwise
You are given an \(N \times N\) matrix. Your task is to rotate the matrix by 90 degrees in the clockwise direction.
The rotation should transform a matrix \(A\) into a matrix \(B\), where each element \(B_{j, N-1-i}\) is equal to \(A_{i, j}\) for \(0 \leq i, j < N\). For example, a 3 x 3 matrix: \[ \begin{bmatrix} 1 & 2 & 3\\ 4 & 5 & 6\\ 7 & 8 & 9 \end{bmatrix} \] becomes \[ \begin{bmatrix} 7 & 4 & 1\\ 8 & 5 & 2\\ 9 & 6 & 3 \end{bmatrix} \]
Your solution should read from the standard input and write to the standard output.
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases. For each test case, the first line contains an integer \(N\) (the size of the matrix). The next \(N\) lines each contain \(N\) space-separated integers, representing the rows of the matrix.
Example:
3 1 2 3 4 5 6 7 8 9
outputFormat
For each test case, output the rotated matrix in the same format: each row on a new line with space-separated integers. The matrices for different test cases are concatenated sequentially in the output (with a newline separating consecutive matrices if needed).
## sample3
3
1 2 3
4 5 6
7 8 9
2
1 2
3 4
1
7
7 4 1
8 5 2
9 6 3
3 1
4 2
7
</p>