#include <bits/stdc++.h>

using namespace std;

int main()
{
	int T, cas, X;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &cas);
		printf("%d ", cas);
		scanf("%X", &X);
		//printf("%d\n", X);
		int S = (X & 0x80000000) > 0;
		int E = (X & 0x7fffFFFF) >> 24;
		int M = (X & 0x00fffFFF);
		//printf("S = %d E = %d M = %d\t", S, E, M);

		int SS = S;
		int EE = (E - 64) * 4;
		int MM = M;

		//zero
		if (MM == 0) {
			//puts("00000000");
			printf("%08X\n", SS << 31);
			continue;
		}
		//cout << EE << ' ' << MM << endl;

		//1 + M
		while (!(MM & 0x800000)) {
			MM = (MM << 1);
			EE--;
		}
		
		//cout << EE << ' ' << MM << endl;
		
		//smaller
		if (EE <= -126) {
			while (EE <= -126) {
				EE++;
				MM >>= 1;
			}
			//too small
			if (MM == 0) {
				printf("%08X\n", SS << 31);
				continue;
			}
			
			//de-normal
			printf("%08X\n", (SS << 31) | MM);
			continue;
		}
		
		//larger
		if (EE > 128) {
			//inf
			printf("%08X\n", (SS << 31) | (255 << 23) | (0));
			continue;
		}

		//normal
		printf("%08X\n", (SS << 31) | ((EE + 127 - 1) << 23) | (MM & 0x7ffFFF));
	}
	return 0;
}

