def josephus_2( n ):
    from math import log
    return 2*(n - 2**(int(log(n,2))))+1
cases= int(raw_input())
current= 0
while current < cases:
    current	+= 1
    n = int(raw_input())
    print josephus_2( n )