Faculty Dividing Powers
Fred Faculty and Paul Power love big numbers. Day after day Fred chooses a random integer and he computes . His friend Paul amuses himself by computing several powers of his randomly chosen integer like , , and so on. On a hot summer day, Fred and Paul got really, really bored, so they decided to play a joke on their buddy Dave Divider. Fred chooses a random integer while Paul chooses a random integer . They want Dave to find the biggest integer such that divides without a remainder, otherwise they will throw a cake in Dave's face.
Because Dave does not like cakes in his face, he wants you to help him finding that integer .
Input
The first line contains the number of test cases . Each of the following lines contains two numbers and .
Output
For each test case, print the maximum integer on a separate line.