#include using namespace std; using ll = long long; using ull = __int128_t; ull modpow(ull a, ll n, ll m) { if (n == 0) return 1; if (n % 2) return a % m * modpow(a, n-1, m) % m; ull t = modpow(a, n/2, m); return t % m * t % m; } bool isPrime(ll x) { if (x == 2) return true; if (x == 1 || x % 2 == 0) return false; ll m = x-1; ll t = m; ll s = 0; while (t % 2 == 0) { t /= 2; ++s; } ll d = m / (1LL << s); for (ll a : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) { if (a == x) return true; ull n = a; n = modpow(n, d, x); int r = 0; if (n == 1) continue; while (n != m) { n = modpow(n, 2, x); ++r; if (r == s) return false; } } return true; } int main(void) { int n; cin >> n; for (int i = 0; i < n; ++i) { ll x; cin >> x; cout << x << " " << isPrime(x) << endl; } return 0; }