import sys
import math
def josephus_2( n ):
    from math import log
    return 2*(n - 2**(int(log(n,2))))+1
T = int(sys.stdin.readline())
for cs in xrange(T):
    n = int(sys.stdin.readline())
    print josephus_2(n)