#K116. Matrix Rotation
Matrix Rotation
Matrix Rotation
You are given an N×N matrix. Your task is to rotate the matrix by 90° clockwise. In mathematical terms, if the given matrix is \(A\) with elements \(A[i][j]\), then the resulting matrix \(B\) should satisfy \(B[j][N-1-i] = A[i][j]\) for all valid indices.
The input consists of one or more test cases. For each test case, you will be given the size of the matrix followed by the matrix elements. You need to output the rotated matrix for each test case.
Note: Use standard input (stdin) to read the input and standard output (stdout) to print the answer.
inputFormat
The input starts with an integer T representing the number of test cases. For each test case:
- An integer N representing the size of the matrix.
- N lines follow, each containing N space-separated integers, representing the matrix.
All input is given via stdin.
outputFormat
For each test case, output the rotated matrix. Each rotated matrix should be printed by outputting N lines, each containing N space-separated integers. Print the result for each test case sequentially without extra lines in between.
The output should be printed via stdout.
## sample1
3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
</p>