#d11303. 矩阵游戏
矩阵游戏
Matrix Game
Problem Description
Little S is playing a game: he has a board of length and width , in which some cells are black (the rest are white).
In one operation he may choose a rectangular region whose length and width are both greater than ; if exactly of its four corner cells are black, he may paint the remaining white corner cell black.
Find how many different boards satisfy both:
- Little S can turn the entire board black after a finite number of operations;
- the number of black cells used is minimal.
Two boards are different if and only if there exists at least one cell with a different color in the two boards. Output the answer modulo .
Input Format
The first line contains a positive integer , the number of test cases.
For each test case, the first line contains two positive integers and .
Constraints: for all data, , , .
Output Format
For each test case, output one integer on a single line: the answer.
Sample Input
2
1 1
2 2
Sample Output
1
4