EDSAC (Electronic Delay Storage Automatic Calculator) was an early digital computer that could store a program in main memory and execute it. Its instructions included operations using an accumulator, and its calculations were based on a 17-bit word type and a 35-bit double word type. Input and output used a 5-bit teleprinter code.
An EDSAC program can be written in a simple assembly language. Each instruction consists of one character, a nonnegative decimal address, and either F or D. F means the full word type, and D means the double word type. For example, the instruction A 128 F means to add the full word value at memory address 128 to the accumulator. This instruction is represented in binary as 11100000100000000. The first 5 bits, 11100, are the opcode for add; the next 11 bits, 00010000000, are operand address 128; and the final bit, 0, means full word. For a double word instruction, the final bit is 1.
EDSAC arithmetic uses fixed-point two's-complement representation. The arithmetic unit treats the binary point as being between the most significant bit, the leftmost bit, and the next bit to its right. Therefore, the range of a 17-bit word value x is -1.0 <= x < 1.0.
| Value | Binary representation |
|---|---|
| -1.0 | 10000000000000000 |
| 1/2 | 01000000000000000 |
| 3/4 | 01100000000000000 |
| -1/2 | 11000000000000000 |
The largest positive real value that can be represented is 01111111111111111 = 0.9999847412109375, and the smallest positive value is 00000000000000001 = 2^(-16) = 0.0000152587890625.
Interestingly, the opcode for add and the teleprinter code for A are both 11100, and the subtract instruction and the character S are both 01100. The 32 characters representable by the teleprinter code are PQWERTYUIOJ#SZK*?F@D!HNM&LXGABCV, and a 5-bit opcode can also represent 32 values. In this order, P is 00000, Q is 00001, and the values increase one by one until V, which is 11111.
However, this assembly language has no dedicated notation for data values. Because of that, an ordinary instruction bit pattern can also be used as a data value. For example, the bit pattern for the constant 3/4, 01100000000000000, is written as S 0 F, and the bit pattern close to 1/3, 00101010101010101, is written as T 682 D.
Given an EDSAC instruction, write a program that outputs the decimal number represented by its bit pattern.
The first line contains the number of test cases P. (1 <= P <= 1000)
Each test case is given on one line as an EDSAC instruction in the form c d s. c is one EDSAC alphabet character. d is an unsigned decimal integer satisfying 0 <= d < 2^11. s is either D or F.
For each test case, output one decimal number corresponding to the given EDSAC instruction in the form [-]b.ddd.... Print the minus sign only for negative numbers. b is either 0 or 1, and the number of digits after the decimal point must be at least 1 and at most 16. Do not print unnecessary trailing zeros.