You are given fractions:
$$({n_1 \over d_1}) / ({n_2 \over d_2}) / ({n_3 \over d_3}) / \cdots / ({n_N \over d_N})$$
Assuming that you can execute the divisions in any way you want, your task is to find the smallest and largest result that can be obtained.
Input consists of several cases. The first line of each case contains a single number . Each of the following lines contains a description of one fraction: -th line () of each case contains two integers and , where , and . You can assume that the value of the product of all , where , does not exceed .
Edit: Changed the limit to the one that was actually used.
The input ends with a single line containing 0.
In the first line output and — the nominator and denominator of the smallest possible result. In the second line output and — the nominator and denominator of the largest possible result. Both should be given as irreducible fractions, with .
Input
3 1 2 3 4 1 3 0
Output
2 9 2 1