ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2205. Natural Numbers

Time limit: 2.0 second
Memory limit: 256 MB
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

inputoutput
3
4 4
4 5
4 6
4
1
1
Problem Author: Vadim Barinov
Problem Source: University academic school olympiad in informatics 2022