I=input for t in range(int(I())):N=int(I());l=N&-N;m=N^l;r=m&-m;print(r-l if l and m else-1)