Little Panda has a thing for powers and modulus and he likes challenges. His friend Lucy, however, is impractical and challenges Panda to find both positive and negative powers of a number modulo a particular number. We all know that refers to the modular inverse of modulo (see Wikipedia).
Since Lucy is impractical, she says that for .
Now she wants Panda to compute .
She also thinks that this problem can be very difficult if the constraints aren't given properly. Little Panda is very confused and leaves the problem to the worthy programmers of the world. Help him in finding the solution.
The first line contains , the number of test cases.
Then lines follow, each line containing , and .