Under construction

Still being built. Things may change

Common Fraction

Interview

Time limit1sMemory limit128 MB

Summary
Reduce each of n fractions to lowest terms by dividing out the greatest common divisor.
Level

Easy3 of 10

Topics
Number theory
Solved
No attempts yet

Problem

A common fraction, also called a simple fraction, is a rational number written as a/ba/b, where the integers aa and bb are the numerator and the denominator. The denominator cannot be zero.

Dividing the numerator and the denominator by the same non-zero number gives a fraction of equal value. That step is called reducing the fraction. A fraction whose numerator and denominator are coprime, meaning the only positive integer that divides both of them is 1, is in lowest terms. For example, 3/93/9 is not in lowest terms because 3 and 9 are both divisible by 3. On the other hand, 3/83/8 is in lowest terms, since the only positive integer that divides both 3 and 8 is 1.

Write a program that reduces the given fractions to lowest terms.

Input

The first line contains the number of fractions nn (1≤n≤1041 \le n \le 10^4).

Each of the next nn lines contains the numerator aa and the denominator bb of one fraction, separated by a space (1≤a≤1061 \le a \le 10^6, 1≤b≤1061 \le b \le 10^6).

Output

For each fraction, in the order it was given, print its lowest terms on one line. Separate the numerator and the denominator with a single space.

Examples1

  1. Example 1

    Input
    5
    1 2
    3 9
    63 462
    11 22
    13 14
    
    Expected output
    1 2
    1 3
    3 22
    1 2
    13 14