#K11151. Diagonal Reflection of a Square Matrix
Diagonal Reflection of a Square Matrix
Diagonal Reflection of a Square Matrix
Given a square matrix \(A\) of size \(N \times N\), you are required to compute its diagonal reflection, which is equivalent to transposing the matrix.
The diagonal reflection means that each element \(A_{i,j}\) in the original matrix is moved to position \(A_{j,i}\) in the output matrix. For example, if the input matrix is:
\( \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix} \)
Then its diagonal reflection will be:
\( \begin{bmatrix} 1 & 4 & 7 \\ 2 & 5 & 8 \\ 3 & 6 & 9 \end{bmatrix} \)
You will be given multiple test cases.
inputFormat
The first line of the input contains an integer \(T\) denoting the number of test cases. Each test case begins with an integer \(N\) indicating the size of the square matrix. The following \(N\) lines each contain \(N\) space-separated integers representing a row of the matrix. A test case where \(N = 0\) indicates an empty grid.
Example:
1 3 1 2 3 4 5 6 7 8 9
outputFormat
For each test case, output the diagonal reflection of the matrix (i.e. its transpose). The output for each test case should consist of \(N\) lines, each containing \(N\) space-separated integers. Separate outputs for different test cases with a blank line.
Example Output:
1 4 7 2 5 8 3 6 9## sample</p>
1
3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 8
3 6 9
</p>