10
71
8497
6364
6530
9199
5754
1508
9388
6992
4494
72
8512
8192
8192
9216
8192
2048
9472
8192
4608

t = int(raw_input())
l = []
while t >= 1:
    n = int(raw_input())

    a = bin(n)


    while 1:
        a = bin(n)
        a = a[2:]
        cntr = 0
        for id,i in enumerate(a):
            if  i == "1":
                cntr += 1
            else :
                if cntr >= 1:
                    cntr -= 1
            if cntr > 1:
                flag = False
                break
            else :
                flag = True
        if flag :
            break
        else :
            pass
        n += 1
    l.append(n)
    t -= 1
for i in l:
    print i