# Survival Strategy - HackerEarth
import math

no_of_tc = input()
for i in range(no_of_tc):
    no_of_players = input()
    row = math.log(no_of_players + 1, 2)
    if row % 1 > 0:
        iid = no_of_players - ((2 ** math.floor(row)) - 1)
    else:
        iid = 2 ** (row - 1)

    print int((iid * 2) - 1)