def f(x): r=[] for i in range(2,int(x**0.5)+1): if x%i==0: r.append(i) while x%i==0: x//=i if x!=1: r.append(x) return r def g(x): r=[] for i in range(1,int(x**0.5)+1): if x%i==0: r.append(i) if i*i!=x: r.append(x//i) return r T=int(input()) for i in range(T): N=int(input()) N=2*N-1 X=f(N) Y=N for j in range(len(X)): Y//=X[j] Y*=X[j]-1 X=g(Y) P=10**12 for j in range(len(X)): if pow(2,X[j],N)==(1%N): P=min(P,X[j]) print(P)