Geek Challenge [SKRZAT] (Base Minus Two)

Time limit1sMemory limit128 MB

Problem

Geek Challenge [SKRZAT] is a very old game from Poland, played on a console with two buttons and a joystick. True to its name, the game communicates in binary: one button means zero and the other means one. It goes one step further and uses a number system whose base is minus two instead of plus two — a representation we will call “Weird Binary”.

In Weird Binary the bit in position $i$ (counted from the right, starting at $0$) has weight $(-2)^i$. The value of a bit string is the sum of the weights of the positions that hold a one. The five-bit patterns and their values are:

Every five-bit pattern, ordered by bit pattern:

BitsValueBitsValueBitsValueBitsValue
00000001000-81000016110008
00001101001-71000117110019
00010-201010-101001014110106
00011-101011-91001115110117
00100401100-410100201110012
00101501101-310101211110113
00110201110-610110181111010
00111301111-510111191111111

The same values, ordered by magnitude:

BitsValueBitsValueBitsValueBitsValue
01010-1000010-21101061001014
01011-900011-11101171001115
01000-80000001100081000016
01001-70000111100191000117
01110-600110211110101011018
01111-500111311111111011119
01100-400100411100121010020
01101-300101511101131010121

Numbers appear on the screen in Weird Binary, and the player answers from the console with a stream of zeroes and ones. Write a program that helps a novice by translating numbers between decimal and Weird Binary.

Input

The first line contains a single integer $n$, the number of queries. Each of the next $n$ lines is one query:

  • a line beginning with b contains a Weird Binary string that must be converted to decimal;
  • a line beginning with d contains a decimal integer that must be converted to Weird Binary.

Every value fits in a 15-bit Weird Binary number, so the decimal range is $-10922$ to $21845$ inclusive.

Output

Print one line per query, echoing the query type and its input string together with the converted result:

  • for a b query: From binary: <string> is <decimal>
  • for a d query: From decimal: <string> is <weird binary>

Reproduce the input string exactly (a Weird Binary input may contain leading zeroes). In a produced Weird Binary result leading zeroes are not allowed, and the value $0$ is written as 0. Match the spacing shown above exactly.