You are given an grid . Each integer from to appears exactly once in the grid.
The sorted grid is the grid where for every .
You may apply the following operation any number of times:
Choose two integers and such that and . Then, inside the subgrid with top-left cell , simultaneously do both swaps:
For each test case, determine whether it is possible to transform the given grid into the sorted grid.