Two numbers and
are considered coprime if they do not have any common prime factors. For example,
and
are coprime, while
and
are not.
Given and
, can you find the largest value of
such that
and
are coprime, and
? You will be given
of these cases.
Input Specification
The first line will contain the integer
, the number of cases. There will either be
case or
cases.
The next lines will contain two integers,
. Note that these integers will not fit in a 32-bit data type (e.g.
int
). Please use a 64-bit data type (e.g. long
).
Output Specification
For each case, output the value of described in the problem statement on its own line. It is guaranteed the value exists.
Sample Input 1
1
14 28
Sample Output 1
27
Sample Input 2
1
30030 126
Sample Output 2
113
Comments