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

import sys
cases= int(sys.stdin.readline())
current= 0
while current < cases:
    current	+= 1
    n = int(sys.stdin.readline())
    print josephus_2( n )