class Rational
  def my_to_f(digit = -1)
    n = numerator()
    d = denominator()
    res = ""
    m = digit != -1 ? digit : 1000000
    m.times{|i|
      res += (n / d).to_s
      n = n % d * 10
      break if digit == -1 && n == 0 && i >= 1
      res += "." if i == 0
    }
    res
  end
end

gets.to_i.times{
  s = gets.strip
  bit = []
  s.each_char{|c|
    x = c.to_i(16)
    4.times{|i|
      bit.push((x >> (3-i) & 1) == 1 ? 1 : 0)
    }
  }
  res = Rational(0,1)
  t = Rational(1,1)
  24.downto(1){|i|
    res += t if bit[i] == 1
    t *= 2
  }
  t = Rational(1,2)
  25.upto(31){|i|
    res += t if bit[i] == 1
    t /= 2
  }
  print bit[0] == 1 ? "-" : ""
  puts res.my_to_f
}