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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
from math import log

def josephus_2( n ):
    return 2*(n - 2**(int(log(n,2))))+1
   
cases = int(raw_input())

while (cases > 0):
	cases = cases - 1
	print josephus_2(int(raw_input()))