#d1902. 数列
数列
Sequence
Problem Description
Xiaoqi loves sequences very much, so she made a sequence problem.
Given two integers , find the number of sequences satisfying:
- the length of sequence is at least ();
- ;
- define an array of length : , and for all , , where denotes binary XOR. The array must satisfy .
How many such sequences are there? Since the result may be large, output the answer modulo .
Input Format
The first line contains an integer (), the number of test cases.
Each of the next lines contains two integers ().
Note: is not necessarily prime.
Output Format
Output lines, each containing one integer: the answer.
Sample Input
3
5 999996
6 99995
7 9994
Sample Output
17
23
29
Constraints
For all data, and .