It's All About the Base#11187

It's All About the Base

1 second
128 megabytes
Very easy

Bessie the cow has been taking computing classes at her local college (or "cow-ledge," in her case), and she has recently become very excited about writing numbers in different bases.

Recall that a number written in base has digit positions representing 1, b, b^2, b^3, and so on, from right to left. For example, in our familiar base- numbering system, the digit positions represent 's, 's, 's, 's, and so on. The sequence of digits , interpreted in base , means

1(1000) + 2(100) + 3(10) + 4(1)

The same sequence of digits , interpreted in base , means

1(125) + 2(25) + 3(5) + 4(1)

which evaluates to in base . Bessie notices that as the base increases, so does the number represented by a fixed sequence of digits. For example, in base represents a larger number than in base .

When writing numbers in base , each digit can range from through b-1. For example, in base , each digit is in the range , while in base , each digit is in the range .

It is also possible to use bases larger than . Computer scientists often use base ("hexadecimal"), where the letters represent digit values from through . For example, in hexadecimal corresponds to

11(4096) + 14(256) + 14(16) + 15

which evaluates to in base .

Bessie is intrigued by the idea of using bases much larger than . She takes a number and writes it down in two different bases and , where both and are in the range . Interestingly, in both cases she obtains a sequence of exactly digits, and every digit happens to be in the range .

Unfortunately, due to Bessie's poor memory, she has now forgotten , and . Given only the two -digit sequences she wrote down, help her determine the two bases and that she used.

Note that because and can be as large as , a program that exhaustively tries every possible pair of bases (nearly 15000^2 possibilities) will not run within the time limit and will not receive full credit.

Input

Begins with an integer , followed by lines, each describing a separate test case. Each test case consists of two -digit numbers. The first is the number written in base , and the second is the same number written in base . The values of , and may be different for each test case.

Output

Print lines, one for each test case. On each line, output the two bases and for the corresponding test case, separated by a space. A unique solution is guaranteed to exist for every test case.

Examples

The number , written in base , is . Written in base , it is .

Example 1

Loading
Loading