n=int(input());
if n<1 or n>1000:
	exit();
for j in range(0,n):
	x=int(input());
	if x<5 or x>100000000:
		x=0;
	else:
		if x<7:
			print 1+2*(x-4);
		else:
			old=5;
			a=7;
			over=0;
			while(a<x):
				old=a;
				a=a*2+1;
			
			if a==x:
				print a;
			
			else:
				a=old;
				print 1+2*(x-a-1);