BSMATH1 - 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

Added by:Jargon
Date:2009-12-04
Time limit:0.100s-1s
Source limit:5000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:ASM32 ASM64 BASH BF C C++ 4.3.2 CPP CPP14 C99 CLPS LISP sbcl D FORTRAN ICK NEM OCAML PAS-GPC PAS-FPC PRLG-swi PYTHON RUBY SCALA SCM guile SCM qobi ST TCL TEXT WHITESPACE
Resource:Own problem

hide comments
2023-11-22 16:12:39
мать ебал автора задавчи

2022-05-20 07:23:14

ID ОГНОО Хэрэглэгчийн нэр: PROBLEM RESULT TIME САНАХ ОЙ LANG
29577991 2022-05-20 07:05:14 Munkhsuld Тэнцсэн, унасан хөрвүүлэлтийн алдаа
edit run - -
C++

4.3.2

29577989 2022-05-20 07:05:08 Tsooj Минут секунд -> секунд accepted 0.02 5.3M
CPP

29577987 2022-05-20 07:04:35 datohileong Давхар давталт 1 Буруу хариулт 0.01 5.4M
CPP

29577986 2022-05-20 07:04:28 datohileong Давхар давталт 1 Буруу хариулт 0.01 5.4M
CPP

29577985 2022-05-20 07:04:25 Tsooj 3 оронтой тоо Буруу хариулт 0.01 5.3M
CPP

29577984 2022-05-20 07:04:24 Tsooj 3 оронтой тоо Буруу хариулт 0.01 5.4M
CPP

29577983 2022-05-20 07:04:16 enx_jinen Үржвэр нийлбэр 1 хөрвүүлэлтийн алдаа - -
C++

4.3.2

29577980 2022-05-20 07:03:34 hhasar Тэмдэгтэд харгалзах код accepted 0.02 5.4M
C++

4.3.2

29577979 2022-05-20 07:03:33 maral_m Факториалын хүрд accepted 0.03 5.4M
CPP

29577978 2022-05-20 07:03:10 Munkhsuld Тэнцсэн, унасан Буруу хариулт
edit run 0.00 5.3M
C++

4.3.2

29577977 2022-05-20 07:02:58 Tugsuubn Тоон үнэлгээнээс үсгэнд accepted 0.02 5.4M
C++

4.3.2

29577976 2022-05-20 07:02:51 mrlgorkd Үржвэр нийлбэр 3 хөрвүүлэлтийн алдаа - -
C++

4.3.2

29577975 2022-05-20 07:02:37 Munkhsuld Тэнцсэн, унасан хөрвүүлэлтийн алдаа
edit run - -
C++

4.3.2

29577974 2022-05-20 07:02:31 maral_m Факториалын хүрд Буруу хариулт 0.01 5.3M
CPP

29577973 2022-05-20 07:02:12 oyuka Оронгийн тоо accepted 0.01 5.3M
C++

4.3.2

29577972 2022-05-20 07:01:54 номинжин Том үсэгт шилжүүл Буруу хариулт 0.00 5.4M
C++

4.3.2

29577971 2022-05-20 07:01:51 hhasar Тэмдэгтэд харгалзах код Буруу хариулт 0.00 5.3M
C++

4.3.2

29577970 2022-05-20 07:01:33 maral_m Факториалын хүрд Буруу хариулт 0.01 5.2M
CPP

29577969 2022-05-20 07:01:14 oyuka Оронгийн тоо хөрвүүлэлтийн алдаа - -
C++

4.3.2

29577968 2022-05-20 07:01:08 hhasar Тоонд харгалзах тэмдэгт accepted 0.02 5.4M
C++

4.3.2

2021-01-12 22:12:43 David
Why is the Java language excluded?

Last edit: 2021-01-12 22:18:57
2017-12-16 04:52:53
Unnecessarily tight time limit for this type of problem, almost lost a compact, elegant Python solution to a dreaded TLE. Looking back though, the tweaked bit that converted TLE to best Python runtime was an important lesson. Thanks Simes for pissing me off by ACing it while I whined ;)

Last edit: 2017-12-16 21:03:00
2015-02-02 11:57:55 Vamsi Krishna Avula
I thought the TL was strict but its quite opposite ;)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.