1707: Sudoku
Memory Limit:64 MB
Time Limit:1.000 S
Judge Style:Text Compare
Creator:
Submit:1
Solved:1
Description

- Rotating the entire puzzle clockwise or counterclockwise.
- Swapping two columns within a 3 × 9 column segment.
- Swapping two rows within a 9 × 3 row segment.
- Swapping entire row or column segments.
- Applying a permutation f of the digits 1 ... 9 to every cell (i.e. replace x by f(x) in every cell).
Input
The input starts with the number of test cases 0 ≤ N ≤ 50 on a single line.
Then for every test case follow nine lines describing last week's puzzle solution, from top to bottom. Each line corresponds to a row in the puzzle and consists of nine digits (1 ... 9), describing the contents of the cell from left to right.
Last week's solution is followed by nine lines describing this week's unsolved puzzle. Here, also, every line corresponds to a puzzle row and every digit (0 ... 9) describes the contents of a cell. 0 indicates that the cell is empty. The rows are presented ordered from top to bottom, and within each row, the cells are ordered from left to right.
After every test case except the last one follows a blank line. Every unsolved puzzle is guaranteed to be uniquely solvable and last week's solution is always a proper sudoku solution.
Output
For every test case, output Yes if the sudoku puzzle can be derived from the given solved puzzle using the allowed operations, or No if this is not possible.
Sample Input Copy
2
963174258
178325649
254689731
821437596
496852317
735961824
589713462
317246985
642598173
060104050
200000001
008305600
800407006
006000300
700901004
500000002
040508070
007206900
534678912
672195348
198342567
859761423
426853791
713924856
961537284
287419635
345286179
010900605
025060070
870000902
702050043
000204000
490010508
107000056
040080210
208001090
Sample Output Copy
Yes
No