from math import gcd def phi(N): M=N prime=set() p=2 while(p*p<=M): while(M%p==0): M//=p prime.add(p) p+=1 if M>1: prime.add(M) res=N for p in prime: res=(res*(p-1))//p return res def lcm(x,y): return (x*y)//gcd(x,y) def solve(A,M): if pow(A,M,M)==0: return M if A==1: return 1 if M==1: return 1 phiM=phi(M) x=solve(A,phiM) L=lcm(phiM,M) return pow(A,x,L) Q=int(input()) for i in range(Q): p=int(input()) print(solve(2,p))