What Base Is This?#1377

What Base Is This?

1 second
64 megabytes
Medium

In positional notation, the position of a digit determines its weight in the value of a number. For example, in base , the number has the digit with weight 10^0, with weight 10^1, and with weight 10^2, giving the value 3 \times 10^2 + 6 \times 10^1 + 2 \times 10^0, or simply 300 + 60 + 2. The same method applies to numbers in other bases. While most people are used to seeing numbers in base , other bases are also possible. For example, in base or base has a completely different value than in decimal.

In this problem, you are given a sequence of pairs of integers. Let's call them and . Your task is to find the smallest base for and the smallest base for (these bases may be different), so that both represent the same value.

For example, consider the pair and . These are not equal if both are interpreted as base . But if is interpreted in base and in base , as base is 1 \times 3^1 + 2 \times 3^0 = 5, and in any base is in decimal. So and can be equal if the correct bases are chosen.

Input

Each line contains a pair of integers and , separated by at least one space. Lines may have leading or trailing spaces, which should be ignored. The bases for and can be any integer from to inclusive; they do not have to be the same. Digits – have their usual values, and uppercase letters – represent values –.

Output

For each pair, print a message as shown in the examples, indicating whether and can be equal in some valid bases. If this is not possible, print an appropriate message as shown in the output examples.

Examples

Example

Input
12 5
15 15
AB 33
1 1
A 9
Output
12 (base 3) = 5 (base 6)
15 (base 10) = 15 (base 10)
AB is not equal to 33 in any base 2..36
1 (base 2) = 1 (base 2)
A (base 11) = 9 (base 10)

Example 1

Loading
Loading