Small Numbers

Time limit2sMemory limit512 MB

Summary
Given positive integers a and b, reduce their sum using common-divisor divisions and factor moves between them. Report the minimum sum and one minimizing pair.
Level

Hard8 of 10

Topics
Number theory, Math, Greedy, Implementation
Solved
No attempts yet

Problem

Little Vlad has two favorite numbers aa and bb. Recently at school he learned division and multiplication, and he immediately started dividing and multiplying his favorite numbers.

He wrote aa and bb in his notebook and came up with three cool operations he wants to perform on his numbers:

  • Divide both numbers by one of their common divisors.
  • Divide aa by one of its divisors gg, multiply bb by gg.
  • Divide bb by one of its divisors gg, multiply aa by gg.

After performing an operation he erases his old numbers and replaces them with the new ones. He may continue performing operations or stop.

Since Vlad is small, he wants the numbers to be smaller. So he tries to minimize the sum of aa and bb, but cannot manage it on his own. Help him determine the minimum sum he can obtain with these operations, and give an example of a final aa and bb with that sum.

Input

Input data contains multiple test cases. The first line contains integer tt, the number of test cases (1≤t≤5001 \le t \le 500).

Each test case is described by a single line containing integers aa and bb (1≤a,b≤1091 \le a, b \le 10^9), Vlad's favorite numbers.

Output

For each test case output one line: a pair with the minimum sum that can be obtained by performing operations from the list.

Examples1

  1. Example 1

    Input
    2
    4 5
    4 6
    
    Expected output
    1 5
    2 3