mathematicians-fight
Source: hackerearth
Difficulty: UNKNOWN_DIFFICULTY

Once a Mathematician was trapped by military people during a world war with his forty colleagues. The colleagues were without any weapons, only the mathematician had a knife. And with no weapons they were not able to fight with the military, so they decided to kill themselves rather than being killed by military.
They all decided that they will stand in a circle and the every third person will 
kill himself but the mathematician didn't like this idea and had no intention 
of killing himself. He calculates where should he stand so that he is the last one left. You have to tell the serial number of last man standing. 
Note:- Instead of every 3rd position it will be every 2nd position and of course the number of colleagues will be much more than 40.

Input:-
The first line of input is an integer N  that specifies the number of test cases. After that every line contains an integer X  which is the number of colleagues.

Output:-
For each test case generate a line containing the position of the colleague who survives. Assume that the colleagues have serial numbers from 1 to n and that the counting starts with person 1, i.e., the first person leaving is the one with number 2.

Constraints:-
1 ≤ N ≤ 1000
5 ≤ X ≤ 100000000

SAMPLE INPUT
4
5
11
45
23987443

SAMPLE OUTPUT
3
7
27
14420455

Explanation

Taking the case of the first test case if there are 5 participants in the circle, the first to go is 2, followed by 4, followed by 1, followed by 5 which leaves 3 at the end.


'''
   
	int main()
	{
	int t;
	cin>>t;
	while(t--)
	{
		long long a;
		cin>>a;
		if(a&(a-1)==0)
		 cout<<"1\n";
		else
		 {
		 	long long n=a,p=2,m=0;
		 	while(p<n)
		 	 {
		 	 	m++;
		 	 	p=2*p;
			  }
			  p=p/2;
			  //cout<<" m->"<<m<<" p->"<<p<<endl;
			  cout<<2*(n-p)+1<<endl;;
		 }
	}
	}
'''
t=eval(input())
while t>0:
	t=t-1
	a=eval(input())
	if a&(a-1)==0:
		print("1\n")
	else:
		n=a
		p=2
		m=0
		while p<n:
			m=m+1
			p=2*p
		p=p/2
		print(2*(n-p)+1)




from math import log

T = int(input())

for i in range(T):
	X = int(input())
	print(2 * (X - 2 ** int(log(X, 2))) + 1)


for _ in range(eval(input())):
	n=eval(input())
	print(int(str(bin(n))[3:]+str(bin(n)[2]),2))