#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)

int main(){
	double a[40];
	int k[40];
	
	int t=1;
	for(int i=24;i>0;i--){
		a[i]=t;
		k[i]=1;
		t*=2;
	}
	double tt=1.0;
	for(int i=25;i<=31;i++){
		tt/=2;
		a[i]=tt;
		k[i]=i-24;
	}
	/*a[25]=0.5; k[25]=1;
	a[26]=0.25; k[25]=1;
	a[27]=0.125; k[25]=1;
	a[28]=0.0625; k[25]=1;
	a[29]=0.03125; k[25]=1;
	a[30]=0.015625; k[25]=1;
	a[31]=0.0078125; k[25]=1;*/
	
	int q;
	cin>>q;
	rep(ppp,q){
		string s,t="";
		cin>>s;
		rep(i,8){
			int b=s[i];
			if('a'<=b&&b<='f')b=10+b-'a';
			else b-=48;
			
			int c[4]={8,4,2,1};
			rep(j,4){
				if(b>=c[j])t+='1';
				else t+='0';
				b%=c[j];
			}
		}
		
		
		double ans=0.0;
		int K=1;
		
		rep1(i,31){
			if(t[i]=='1'){
				ans+=a[i];
				K=max(K,k[i]);
			}
		}
		
		if(t[0]=='1')printf("-");
		
		if(K==1)printf("%.1f\n",ans);
		if(K==2)printf("%.2f\n",ans);
		if(K==3)printf("%.3f\n",ans);
		if(K==4)printf("%.4f\n",ans);
		if(K==5)printf("%.5f\n",ans);
		if(K==6)printf("%.6f\n",ans);
		if(K==7)printf("%.7f\n",ans);
		if(K==8)printf("%.8f\n",ans);
	}
}