#P51384. 「COCI 2020.11」Euklid

「COCI 2020.11」Euklid

Description

It is rarely mentioned that Euclid’s grandma was from Vrsi in Croatia. It is from there that Euclid’s less known (but equally talented in his youth) cousin Edicul comes from.

It happened one day that they were playing “invent an algorithm”. Edicul writes two positive integers on the sand. Then he does the following: while neither number on the sand is 11, he marks them as (a,b)(a, b) so that aba \geq b. Then the numbers are erased and he writes (ab,b)( \left \lfloor \dfrac{a}{b} \right \rfloor, b) on the sand, and repeats the process. When one of the two numbers becomes 11, the other is the results of his algorithm.

Formally, if aa and bb are positive integers, the result R(a,b)R(a, b) of Edicul’s algorithm is:

R(a,b)={R(b,a) if a<bR ⁣(ab ⁣,b) if ab>1a if ab=1R(a,b)= \begin{cases} R(b,a) & \text{ if } a < b \\ R \!\left( \left\lfloor \dfrac{a}{b} \right\rfloor\! , b \right) & \text{ if } a \geq b > 1 \\ a & \text{ if } a \geq b = 1 \end{cases}

Euclid thinks for a while, and says: “Edicul, I have a better idea...”, and the rest is history. Unfortunately, Edicul never became famous for his idea in number theory.

This sad story inspires the following problem: Given positive integers gg and hh, find positive integers aa and bb such that their greatest common divisor is gg, and the result of Edicul’s algorithm R(a,b)R(a, b) is hh.

Input Format

The first line contains a single integer tt(1t401 \leq t \leq 40) – the number of independent test cases.

Each of the following tt lines contains two positive integers gig_i and hih_i (hi2h_i \geq 2).

Output Format

Output tt lines in total. For the ii-th testcase, output positive integers aia_i and bib_i such that gcd(ai,bi)=gi\gcd(a_i, b_i) =g_i and R(ai,bi)=hiR(a_i, b_i) =h_i.

The numbers in the output must not be larger than 101810^{18}. It can be proven that for the given constraints, a solution always exists.

If there are multiple solutions for some testcase, output any of them.

Example 1

1
1 4
99 23
2
3 2
5 5
9 39
5 5

Scoring

In all subtasks, 1gi2×1051 \leq g_i \leq 2 \times 10^52hi2×1052 \leq h_i \leq 2 \times 10^5.

Subtask Constraints Point
11 gi=hig_i=h_i 44
22 hi=2h_i=2 77
33 gi=hi2g_i=h_i^2
44 gi,hi20g_i,h_i \leq 20 1414
55 gi,hi2×103g_i,h_i \leq 2 \times 10^3 3636
66 No additional constraints. 3232