Floating-Point Format Conversion

No attempts yetTime limit1sMemory limit256 MB

Problem

A number written in the obsolete Gould floating-point format has to be converted to the IEEE 754 single-precision format as accurately as possible.

The Gould format is 32 bits.

It has one sign bit, 7 exponent bits and 24 mantissa bits, and those 32 bits are written as 8 hexadecimal digits. Up to the first three bits of the mantissa may be 0. The value the format holds is

value=(1)S×16EXP64×MANTISSA224\text{value} = (-1)^{S} \times 16^{EXP - 64} \times \frac{MANTISSA}{2^{24}}

SS is the sign bit, EXPEXP is the exponent field, and MANTISSAMANTISSA is the mantissa field. Zero is written as 32 zero bits.

The IEEE 754 single-precision format is also 32 bits.

It has one sign bit, 8 exponent bits and a 24 bit significand. In a normalized number the leading bit of the significand is always 1, so that bit is not stored and the mantissa field is written with 23 bits.

If the exponent field is neither 0 nor 255, the number is normalized and its value is

value=(1)S×2EXP127×(1+MANTISSA223)\text{value} = (-1)^{S} \times 2^{EXP - 127} \times \left(1 + \frac{MANTISSA}{2^{23}}\right)

If the exponent field is 255 and the mantissa field is 0, the number is positive infinity or negative infinity. The sign bit decides which one.

If the exponent field is 255 and the mantissa field is not 0, the number is not a number, and this problem does not deal with it.

If the exponent field is 0 and the mantissa field is 0, the number is +0 or -0. The sign bit tells the two apart.

If the exponent field is 0 and the mantissa field is not 0, the number is subnormal and its value is

value=(1)S×2126×MANTISSA223\text{value} = (-1)^{S} \times 2^{-126} \times \frac{MANTISSA}{2^{23}}

Given a number written in the Gould format, convert it by these rules.

  • If the value is 0, print +0.
  • If the value is too large for a normalized IEEE number, print positive infinity or negative infinity. The sign follows the sign bit.
  • If the value is too small for a normalized IEEE number, print the result of the subnormal formula when the value can be written as a subnormal number, and +0 or -0 when it cannot. The sign follows the sign bit.
  • In every other case, print the normalized IEEE value.

When the significand is moved over, pad the missing low places with 0 if there are not enough bits, and drop the leftover low bits if there are too many. Do not round.

Input

The first line has the number of test cases PP. (1P10001 \le P \le 1000)

Each of the next PP lines has the number of the test case and one number written in the Gould format, separated by a space. That number is 8 hexadecimal digits made only of the digits 0 to 9 and the uppercase letters A to F.

Output

For each test case, print the number of the test case and the converted IEEE value on one line, separated by a space. Write the IEEE value as 8 uppercase hexadecimal digits.