#include using namespace std; using int64 = long long; const int mod = 1e9 + 7; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 > &p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template< typename T = int64 > vector< T > make_v(size_t a) { return vector< T >(a); } template< typename T, typename... Ts > auto make_v(size_t a, Ts... ts) { return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...)); } template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); } template< typename F > struct FixPoint : F { explicit FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } namespace FastPrimeFactorization { using uint128_t = __uint128_t; template< typename T, typename U > T mod_pow(T x, U n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; } bool miller_rabin_primality_test_uint64(uint64_t n) { int s = __builtin_ctzll(n - 1), j; uint64_t d = (n - 1) >> s; for(uint64_t a : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) { uint64_t y = mod_pow< uint128_t >(a, d, n); if(y == 1 || y == n - 1) continue; for(j = s - 1; j > 0; j--) { y = uint128_t(y) * y % n; if(y == n - 1) break; } if(j == 0) return false; } return true; } bool miller_rabin_primality_test_uint32(uint32_t n) { uint32_t d = n - 1; while(d % 2 == 0) d /= 2; for(uint32_t a : {2, 7, 61}) { if(n <= a) break; uint32_t t = d; uint32_t y = mod_pow< uint64_t >(a, t, n); while(t != n - 1 && y != 1 && y != n - 1) { y = uint64_t(y) * y % n; t *= 2; } if(y != n - 1 && t % 2 == 0) return false; } return true; } bool is_prime(uint64_t n) { if(n == 2) return true; if(n == 1 || n % 2 == 0) return false; if(n < uint64_t(1) << 32) return miller_rabin_primality_test_uint32(n); return miller_rabin_primality_test_uint64(n); } /* TODO vector< int64_t > prime_factor(int64_t n) { if(n <= 1) return {}; int64_t p = brent(n); if(p == n) return {p}; auto l = prime_factor(p); auto r = prime_factor(n / p); copy(begin(r), end(r), back_inserter(l)); return l; } */ }; int main() { int N; cin >> N; while(N--) { int64 x; cin >> x; cout << x << " " << FastPrimeFactorization::is_prime(x) << "\n"; } }