result = []
sushu = [3 ,7 ,127 ,8191 ,131071 ,524287 ,2147483647]
n = int(input())
for i in range(1,n+1):
x = int(input())
j = 0
for a in range(7):
sushu1 = sushu[j]
if sushu1 >= x:
result.append(sushu1)
break
else:
j += 1
continue
for b in result:
print(b)