Beads of colors are connected together into a circular necklace of beads (n \leq 10^9). You are to calculate how many different kinds of necklaces can be made. You do not have to use all colors in a necklace. Necklaces that are equivalent by rotation around the center are considered the same; such repetitions should be ignored.
Output the answer modulo .
The first line contains the number of test cases (x \leq 3500). Each of the following lines contains two numbers and (1 \leq n \leq 10^9, 1 \leq p \leq 30000).
For each test case, print the answer on a separate line.
Example 1