#include #define rep(i,n) for(int i=0;i ; using pll = pair; const ll INF = 1e18; const int MOD = 1000000007; long long modpow(long long x, long long n,long long mod) { long long ret = 1; while (n > 0) { if (n & 1) ret = (ret * x) % mod; x = (x * x) % mod; n >>= 1; } return ret; } bool Miller_Rabin(long long x){ if(x == 0) return false; if(x == 1) return false; if(x == 2) return true; if(x%2 == 0) return false; long long d = x - 1; while(d%2 == 0) d /= 2; random_device rand; mt19937 mt(rand()); uniform_int_distribution random_maker(1,x-1); for(int i = 0;i < 20; ++i){ long long a = modpow(random_maker(mt),d,x); long long s = d; while(s != x-1 && a != 1 && a != x-1){ a = (a * a)%x; s <<= 1; } if(a != x-1 && s%2 == 0) return false; } return true; } int main(){ int n; cin >> n; while(n--){ ll x; cin >> x; cout << x << " " ; cout << (Miller_Rabin(x) ? 1 : 0) << endl; } return 0; }