#define ll long long #define ull unsigned long long #define bool int #define T 1 #define F 0 ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n%2?x=x*a%m:0,a=a*a%m;return x;} ll mumll(ll p,ll q,ll m){ull x=0;for(;q;q/=2)q&1?x=(x+p)%m:0,p=((ull)p+p)%m;return(ll)x;} ll pomll(ll a,ll n,ll m){ll x=1;for(;n;n/=2)n&1?x=mumll(x,a,m):0,a=mumll(a,a,m);return x;} //ミラーラビン ll sus[]={2,7,61,0}; //ll susll[]={2,3,5,7,11,13,17,19,23,29,31,37,0}; ll susll[]={2,325,9375,28178,450775,9780504,1795265022,0}; bool isp(ll n){ if(n==2)return T; if(n<2||n%2==0)return F; ll d=(n-1)/(n-1&1-n); if(n<(1LL<<31)){ for(int i=0;sus[i];i++){ if(sus[i]>=n)return T; ll t=d,a=pom(sus[i],t,n); if(a==1||a==n-1)continue; while((t*=2)!=n-1&&(a=a*a%n)!=n-1&&a!=1); if(t==n-1||a==1)return F; } return T; } for(int i=0;susll[i];i++){ if(susll[i]%n==0)continue; ll t=d,a=pomll(susll[i],t,n); if(a==1||a==n-1)continue; while((t*=2)!=n-1&&(a=mumll(a,a,n))!=n-1&&a!=1); if(t==n-1||a==1)return F; } return T; } ll n,x; main(){ scanf("%d",&n); while(n--){ scanf("%lld",&x); printf("%lld %d\n",x,isp(x)); } }