Rational Numbers from Repeating Fractions#1021

Rational Numbers from Repeating Fractions

1 second
64 megabytes
Very easy

Any rational number can be written in the form , where and are integers. All rational numbers less than (that is, those for which p < q) can be written as a decimal fraction, but this expansion may require some digits to repeat. For example, the rational number has the decimal representation Here, the pair of digits and repeat indefinitely. Typically, these repeating digits are shown with a horizontal bar above them.

If the decimal representation of a rational fraction is given (with the repeated digits indicated, if necessary), we can determine the rational fraction (that is, express it as for integers and ) using the following algorithm.

Suppose there are non-repeating digits just after the decimal point, followed by a group of repeating digits. In the example , we have k = 1 (for digit ) and j = 2 (for digits and ). To recover the original number (), compute the numerator and denominator as follows:

After computing, the numerator will be:

The denominator is 1000 - 10 = 990. The calculated numerator and denominator will always be integers for the given inputs. Thus, we write the result as the fraction . Reducing the fraction gives as expected.

Input

The input consists of several test cases, each on a separate line, ending with a line containing a single . Each test case consists of an integer , followed by one or more spaces, followed by the decimal expansion in the form (where each is a decimal digit). There may be up to digits in total after the decimal point (i.e., k + j \leq 9).

Output

For each test case, output the test case number (numbered from ), then the rational number in the form , reduced to lowest terms, each on a separate line.

Examples

Example 1

Loading
Loading