'''
Created on Mar 1, 2013

@author: Hari
'''
import math

if __name__ == '__main__':
    no_of_testcase = int(raw_input())
    
    # Check whether 1<=no_of_testcases<=1000
    if (no_of_testcase < 1 ) or (no_of_testcase > 1000):
        print 'Invalid no of test cases'
    else:
        count = 1
        no_of_people = []
        while count <= no_of_testcase:
            tmp = int(raw_input())
            # Check whether 5<=no_of_people<=100000000
            if (tmp < 5) or (tmp > 100000000):
                print "Invalid no of people count"
            else:
                no_of_people.append(tmp)
                count = count + 1
        
        for people in no_of_people:
            nearest_power_of_two = int(math.log(people,2))
            if nearest_power_of_two == 0:
                answer = 1
            else:
                subtract_value = people - int(math.pow(2, nearest_power_of_two))
                answer = subtract_value*2 + 1
                print answer