program bzoj_3884; var t,p:longint; functioncalc_phi(x:longint):longint; var cnt,i:longint; begin cnt:=x; for i:=2to trunc(sqrt(x)) doif x mod i=0then begin cnt:=cnt div i*(i-1); while x mod i=0do x:=x div i; end; if x=1thenexit(cnt) elseexit(cnt div x*(x-1)); end; functionqp(x,k,m:longint):longint; var p:int64; begin qp:=1; p:=x; while k<>0do begin if k and1=1then qp:=(qp*p)mod m; p:=(p*p)mod m; k:=k>>1; end; end; functioncount(p:longint):longint; var k,phi,ans:longint; begin if p=1thenexit(0); k:=0; while p and1=0do begin p:=p>>1; inc(k); end; phi:=calc_phi(p); ans:=(count(phi)+phi-k mod phi)mod phi; exit((qp(2,ans,p)mod p)<<k); end; begin readln(t); for t:=1to t do begin readln(p); writeln(count(p)); end; end.