killing-white-walkers

"N"  White Walkers are positioned  in a circle from "1" to "N". First  (No. 1) White Walker has a dragonglass . He kills the next White Walker (i.e. No. 2) and passes the dragonglass to the next (i.e. No. 3) who kills the 4th and passes the weapon to 5th White Walker. This way alternate killing of White Walkers goes on until only 1 survives. At what position is the survivor? 

Assumption: Always the first White Walker starts to kill with the dragonglass.

Input
'T' No. of test cases.
'N' Total number of White Walkers in  a circle .

Output
The position of the White Walker who survives.

Constraints:
 1 ≤ N ≤ 10^5
 1 ≤ T ≤ 100

SAMPLE INPUT
3
100
10
4

SAMPLE OUTPUT
73
5
1

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t = int(input())

while t > 0:
	t = t - 1
	
	n = int(input())
	
	if n == 0:
		print("0")
		continue
	
	m = 1
	
	while 1:
		temp = m*2
		if temp > n:
			break
		m = temp
	
	ans = 2*(n-m)+1
	print(ans)