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

from math import log
def josephus_2( n ):
   return 2*(n - 2**(int(log(n,2))))+1

maxTestCases = int(raw_input());
for i in range(maxTestCases):
    testCase = int(raw_input());
    print josephus_2(testCase);