Problem: Moamen and Ezzat are playing a game. They create an array of non-negative integers where every element is less than .
Moamen wins if .
Here denotes the bitwise AND operation, and denotes the bitwise XOR operation.
Please calculate the number of winning for Moamen arrays .
As the result may be very large, print the value modulo ().
Input Format: The first line contains a single integer ()— the number of test cases.
Each test case consists of one line containing two integers and (, ).
Output Format: For each test case, print a single value — the number of different arrays that Moamen wins with.
Print the result modulo ().
Note: In the first example, , . As a result, all the possible arrays are , , , , , , , and .
Moamen wins in only of them: , , , , and .