#P1864H. Asterism Stream
Asterism Stream
Description
Bogocubic is playing a game with amenotiomoi. First, Bogocubic fixed an integer , and then he gave amenotiomoi an integer which is initially equal to .
In one move amenotiomoi performs one of the following operations with the same probability:
- increase by ;
- multiply by .
Bogocubic wants to find the expected number of moves amenotiomoi has to do to make greater than or equal to . Help him find this number modulo .
Formally, let . It can be shown that the answer can be expressed as an irreducible fraction , where and are integers and . Output the integer equal to . In other words, output such an integer that and .
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The only line of each test case contains one integer ().
For each test case, output a single integer — the expected number of moves modulo .
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The only line of each test case contains one integer ().
Output
For each test case, output a single integer — the expected number of moves modulo .
Note
In the first test case, without any operations, so the answer is .
In the second test case, for , here is the list of all possible sequences of operations and their probabilities:
- , the probability is ;
- , the probability is ;
- , the probability is ;
- , the probability is ;
- , the probability is ;
- , the probability is .
So the expected number of moves is .
In the third test case, for , the expected number of moves is .
In the fourth test case, for , the expected number of moves is .