Finding the Two Bases

No attempts yetTime limit1sMemory limit256 MB

Problem

Bessie the cow is taking computing classes at her local college, and she recently learned how to write numbers in different bases.

A number written in base BB has digit places representing 11, BB, B2B^2, B3B^3, and so on from right to left. In the familiar base 1010 system the places represent 11, 1010, 100100, 10001000, and so on. The digit sequence 12341234 read in base 1010 means 1(1000)+2(100)+3(10)+4(1)1(1000) + 2(100) + 3(10) + 4(1). The same digit sequence read in base 55 means 1(125)+2(25)+3(5)+4(1)1(125) + 2(25) + 3(5) + 4(1), which is 194194 in base 1010. When the base grows, the number represented by a fixed digit sequence grows too. For example, 12341234 in base 77 is larger than 12341234 in base 66.

In base BB each digit ranges from 00 to B1B-1, so base 1010 digits run from 00 to 99 and base 55 digits run from 00 to 44. Bases larger than 1010 are allowed. Computer scientists often use base 1616, where the letters A to F stand for the digit values 1010 to 1515. In base 1616 the sequence BEEF means 11(4096)+14(256)+14(16)+1511(4096) + 14(256) + 14(16) + 15, which is 4887948879 in base 1010.

Bases much larger than 1010 interest Bessie. She took a number NN and wrote it down in two different bases XX and YY, both between 1010 and 1500015000. In both cases she got a sequence of 33 digits, and every one of those digits was between 11 and 99. Bessie has since forgotten NN, XX, and YY. Given only the two 3-digit sequences she wrote down, find the two bases XX and YY she used.

Because XX and YY can be large, a program that tries every possible pair (X,Y)(X, Y) checks nearly 15000215000^2 possibilities and does not finish within the time limit.

Input

The first line contains an integer KK. Each of the next KK lines holds one test case, made of two 3-digit numbers. The first is a number NN written in base XX, and the second is the same NN written in base YY. NN, XX, and YY may differ from test case to test case.

Output

Print KK lines, one per test case. On each line print XX and YY for that test case, separated by a single space. Each test case is guaranteed to have exactly one answer.

Hint

The number 88928892 written in base 4747 is 419419, and written in base 3535 it is 792792.