Assessment
Vasya loves to program. He also loves science fiction. Once on vacation, having read books with his friend, Petya, Vasya decided to devise a formula showing the growth of population on Mars. By estimations Wasi after N years of life, the world population of Martians should be S_N_{ }Martians, where S_N_{ }determined by the formula:
Peter, after Vasya told him his theory, doubts and decided to calculate this number on your computer to verify its authenticity. Moreover, Peter recently read an intelligent book on programming, so he thinks that it does not take much time.
You are invited to do the same, but without having to read smart books. Note that for your convenience to bring S_N modulo M.
Input
The first line of input contains the number of tests. For each test in a separate row contains the number N – the age of the planet Mars and the number of M - module. 0 < N <= 1000000000, 0 < M <= 1000000000.
Output
For each test in the output file will contain the string containing the expected number of Martians after N years of life on the planet of M.