#C3260. Matrix Rotation
Matrix Rotation
Matrix Rotation
You are given a matrix of dimensions \(N \times M\). Your task is to rotate the matrix by 90° clockwise. The rotated matrix will have dimensions \(M \times N\). Specifically, the element at position \((i,j)\) in the original matrix moves to position \((j, N-i+1)\) in the rotated matrix.
Example:
Input matrix: 1 2 3 4 5 6 7 8 9</p>Rotated matrix: 7 4 1 8 5 2 9 6 3
Note: The input will contain multiple test cases.
inputFormat
The first line of the input contains an integer \(T\) denoting the number of test cases. For each test case, the first line contains two space-separated integers \(N\) and \(M\) — the number of rows and columns of the matrix respectively. This is followed by \(N\) lines, each containing \(M\) space-separated integers representing the matrix.
outputFormat
For each test case, output the rotated matrix. Each row of the rotated matrix should be printed on a separate line with its elements separated by a single space. Separate the output of different test cases with a blank line.
## sample2
3 3
1 2 3
4 5 6
7 8 9
2 4
1 2 3 4
5 6 7 8
7 4 1
8 5 2
9 6 3
5 1
6 2
7 3
8 4
</p>