Vadim works in the research department of a large IT company. He doesn’t have to program often, but he has to study the simplest concept in mathematics — natural numbers — every day. He has connected natural numbers in many ways! Today, he decided to connect them in his own way.
Two different numbers a, b are considered connected if either a is the largest divisor of b that is not equal to b, or b is the largest divisor of a that is not equal to a.
A path is defined as a sequence of distinct natural numbers [a1, a2, … , ak] such that for all i in [1, k−1], ai and ai+1 are connected, and k ≥ 1.
The price of a path is the minimum value of ai in the sequence.
Now Vadim is curious about certain pairs of numbers: whether there is a path between them, and if so, what the maximum price of that path can be.
Input
The first line contains a single integer N — the number of pairs of numbers that Vadim wants to inquire about (1 ≤ N ≤
5 · 105).
Each of the following N lines contains two numbers ai, bi separated by a space — the next pair of numbers that Vadim wants to inquire about (1 ≤ ai, bi ≤ 107).
Output
Output N lines. In the i-th line, output −1 if there is no path between ai and bi; otherwise, output a single integer — the maximum price of the path between ai and bi.
Sample
| input | output |
|---|
3
4 4
4 5
4 6
| 4
1
1
|
Problem Author: Vadim Barinov
Problem Source: University academic school olympiad in informatics 2022