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 )
ZGVmIGpvc2VwaHVzXzIoIG4gKToKICAgIGZyb20gbWF0aCBpbXBvcnQgbG9nCiAgICByZXR1cm4gMioobiAtIDIqKihpbnQobG9nKG4sMikpKSkrMQpjYXNlcz0gaW50KHJhd19pbnB1dCgpKQpjdXJyZW50PSAwCndoaWxlIGN1cnJlbnQgPCBjYXNlczoKICAgIGN1cnJlbnQJKz0gMQogICAgbiA9IGludChyYXdfaW5wdXQoKSkKICAgIHByaW50IGpvc2VwaHVzXzIoIG4gKQ==