You are given a chessboard consisting of ‘N’ rows and ’M’ columns. Rows are numbered from 0 to ‘N-1’ and columns are numbered from 0 to ‘M-1’. Cell(i, j) is the cell at the intersection of the ith row and the jth column.
A knight is a chess piece that can move from cell (x1, y1) to the cell (x2, y2) if one of the following conditions is met:
|x1−x2| = 2 and |y1−y2| = 1, or
|x1−x2| = 1 and |y1−y2| = 2.
A knight cannot move outside the chessboard.
Initially a knight is placed at the cell(0, 0) of this chessboard, Moving according to the rules of chess, the knight must visit each cell exactly once. Find out the order of each cell in which they are visited.
Note :
1. There are multiple possible orders in which a knight can visit each cell of the chessboard exactly once. You can find any valid order.
2. It may be possible that there is no possible order to visit each cell exactly once. In that case, return a matrix having all the values equal to -1.
Example :
Consider an 8*8 chessboard, one possible order for visiting each cell exactly once is shown in the image below. Numbers in cells indicate the move number of the Knight.

The first line of input contains an integer ‘T’ denoting the number of test cases.
The next T lines represent the ‘T’ test cases.
The first line of each test case contains two space-separated integers ‘N’ and ‘M’ representing the number of rows and columns in the chessboard respectively.
Output format :
For each test case, In a separate line print ‘Possible’ If knight tour exist otherwise print ’Impossible’
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N, M <= 8
Where ‘T’ is the total number of test cases, ‘N’, ‘M’ is the number of rows and columns respectively.
Time limit: 1 sec
2
1 2
8 8
Impossible
Possible
Test case 1 :
In this case, it is not possible to visit each cell exactly once. Knight cannot move from cell (0, 0) to any other cell. ‘Impossible’ will be the output if you report it correctly.
Test case 2 :
See the problem statement for an explanation.
2
5 5
1 3
Possible
Impossible
Find out all possible ways to visit each cell of the chessboard exactly once, and verify whether it is a possible knight tour or not.
There are N*M cells in the chessboard thus, we can assign a unique integer between 0 to N*M-1 to each cell in (N*M)! Ways. For each of these ways, we will check whether it represents a possible knight tour or not. We can one by one generate all the permutations using the nextPermuation method as described below.
Algorithm
O(N*M*(N*M!)), where ‘N’, ‘M’ is the number of rows and columns respectively.
There are N*M! Permutation and for each permutation, we take O(N*M) time to verify whether it is a valid knight tour or not. Thus, the final time complexity will be
O(N*M*(N*M!)).
O(N*M), where ‘N’, ‘M’ is the number of rows and columns respectively.
The size of the matrix order is N*M. Thus, the final space complexity will be O(N*M).