n=int(raw_input())
for i in range(n):
	j=int(raw_input())
	start=1
	end=j
	it=2
	if not j%2==0:
		start+=it
	else:
		end-=1
	while not start==end:
		if((end-start+it)%(it*2)==0):
			if end-it>0: end-=it
		else:
			if start+it*2<=end: start+=(it*2)
		it*=2
	
	print start