test = input()
t=0
def max2(n):
  i=1
  while i<n:
    i*=2
  return i/2
  
def josephus( n):
     a=n-max2(n)
     a*=2
     a+=1
     return a
while t < test:
  o=input()
  print josephus(o)
  # print ""
  t+=1