#K50052. Matrix Transformation Check
Matrix Transformation Check
Matrix Transformation Check
Given two square matrices \(A\) and \(B\) of size \(n \times n\), determine whether matrix \(B\) can be obtained from matrix \(A\) by performing a sequence of \(90^\circ\) clockwise rotations.
You are allowed to rotate the matrix any number of times (including zero). A single \(90^\circ\) clockwise rotation transforms the matrix such that for every element at position \((i, j)\) in \(A\), it moves to position \((j, n-i-1)\). Check if it is possible to obtain \(B\) from \(A\) using this operation.
inputFormat
The first line contains an integer \(t\) representing the number of test cases. Each test case is formatted as follows:
- An integer \(n\) representing the size of the matrices.
- The next \(n\) lines each contain \(n\) space-separated integers representing the initial matrix.
- The following \(n\) lines each contain \(n\) space-separated integers representing the target matrix.
outputFormat
For each test case, output a single line containing either "Possible" if the target matrix can be obtained from the initial matrix using some (possibly zero) rotations of \(90^\circ\) clockwise, or "Impossible" otherwise.
## sample3
2
1 2
3 4
3 1
4 2
3
1 2 3
4 5 6
7 8 9
7 4 1
8 5 2
9 6 3
2
1 2
3 4
1 2
4 3
Possible
Possible
Impossible
</p>