spoj#BSMATH1. Math with Bases (Easy)

Math with Bases (Easy)

Little Ben had just learned different bases in math. He learned very quickly how to add and subtract in multiple bases, so his teacher provided him with a worksheet to work on. Each section provided a different base and gave an example.

Unfortunately, Little Ben's teacher forgot to write what base each question was in! Please help Little Ben do his homework; he'll be very grateful!

Input

The first line of input contains an integer n (1 ≤ n < 36) that indicates the amount of sections (test cases). Each test case is as follows:

A - B = C
I
X1 op Y1 =
X2 op Y2 =
...
XI op YI =

where A - B = C is the correct example, I (1 ≤ I ≤ 1000) is the number of questions in that section, Xi and Yi are the operands of each problem (Xi = |Xi|, Yi = |Yi|), and op is either + or -, denoting addition or subtraction.


Output

Your program should output in the following format:

SECTION 1 (BASE b)
X1 op Y1 = Z1
X2 op Y2 = Z2
...
Xi op Yi = Zi
SECTION 2 (BASE b)
X1 op Y1 = Z1
X2 op Y2 = Z2
...
Xi op Yi = Zi
...
SECTION N (BASE b)
X1 op Y1 = Z1
X2 op Y2 = Z2
...
Xi op Yi = Zi

where Zi is the solution to Xi op Yi, and b is the base used. (2 ≤ b ≤ 36). If the base is ambiguous, use the smallest base for which the example is correct and the questions are valid. You may assume all solutions fit inside a 64-bit integer and that each base will appear at most once.

 

Example

Input:

4
110 - 101 = 1
2
1111111 + 1 =
100 - 1 =
177 + 1 = 200
2
7712347 + 7 =
11111 + 7777 =
ZAP + DZ = ZOO
1
E + PI =
10 + 1 = 11
1
5 + 5 =

Output:

SECTION 1 (BASE 2)
  1111111 + 1 = 10000000
  100 - 1 = 11
SECTION 2 (BASE 8)
  7712347 + 7 = 7712356
  11111 + 7777 = 21110
SECTION 3 (BASE 36)
  E + PI = PW
SECTION 4 (BASE 6)
  5 + 5 = 14

Notes:

  • large input/output data, be careful with certain languages
  • Tricky input/output; please read problem statement carefully