#SL2310D. Do You Like Interactive Problems?
Do You Like Interactive Problems?
Do You Like Interactive Problems?
There is an integer satisfying . You know but you don't know .
You can do the following guessing: pick an random integer uniformly satisfying (your may equal to previous queries), and you will be told if . You will stop asking if there is only one possible satisfying all the conditions.
Given , if is picked randomly uniformly, what's your expected number of queries?
Input
The first line contains an integer denothing the number of test cases.
For each test case, the only line contains an integer .
Output
For each test case, output one integer denoting the expected number of queries modulo .
Formally, it can be proven that the sought expected value can be represented as an irreducible fraction which satisfies , and there is a unique integer satisfies and . Find this .
Example
2
1
2
0
1