After getting rejected by his crush for 7th time, Rakib decided to leave all these silly worldly things and sink into the ocean of books. For some reasons, he started to like the letter ‘S’ from then. Anyways, he has invited his friends on a party and arranged a weird contest. Each person (including Rakib) takes a book from his collection and sits in n chairs numbered serially from 1 to . The -th person (according to chair number) gets a book consisting of words and among them, words contain the letter ‘S’.
The game goes as follows. At each round, everyone randomly opens a page from his own book and then randomly chooses a word. If no one gets a word which contains ‘S’, the game goes to next round. Otherwise among all the persons who got a word containing ‘S’, the person with the minimum chair number is declared the winner and the game ends.
As you might suspect, everyone wants to know the probability of them winning the contest. Can you help them?
It can be shown that all the probabilities can be shown as where and are co-prime integers and . Print the value of for each probability.
The first line contains the number of test cases (). Each test case begins with a line containing a single integer (), the number of people in the party (including Rakib). Each of the following lines contain two integers, and (, ).
For each case, output integers in a line separated by spaces. The -th integer should be the probability of the -th person winning the game as , for and defined above.
Input | Output |
---|---|
2 2 1 2 2 3 3 1 2 4 6 3 4 | 200000002 800000006 869565224 913043485 217391306 |
Let be a prime. It can be shown that for any integer (), there exists a unique integer () such that . This is called the modular inverse of with respect to and is also expressed as .
Fermat's Little Theorem: If is a prime and is an integer co-prime with , then .