/* */
/* */
#pragma GCC optimize ("O3")
void solve(); /* この関数に問題ごとの処理を書く */
#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#else
#define NDEBUG /* のincludeより前に定義する必要がある */
#define debug false
#endif
#include
#include
#include
#include */
/*
N < 2**20: brute-force
O(√N)
otherwise: Miller-Rabin primality test
O(11(logN)^2); 64bit以上で理論的にはO((logN)^4)
*/
/*!
https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
http://joisino.hatenablog.com/entry/2017/08/03/210000
https://ja.wikipedia.org/wiki/%E3%83%9F%E3%83%A9%E3%83%BC%E2%80%93%E3%83%A9%E3%83%93%E3%83%B3%E7%B4%A0%E6%95%B0%E5%88%A4%E5%AE%9A%E6%B3%95
*/
VI rab_prime_mr_as = { 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 };
bool is_prime(int n) {
assert(n >= 0);
if(n <= 1) return false;
/*if(n % 2 == 0) { return n == 2; }
if(n % 3 == 0) { return n == 3; }
if(n < (1<<20)) {
for(int i = 5; i * i <= n; i += 6) {
if(n % i == 0 || n % (i + 2) == 0) { return false; }
}
return true;
} else*/ {
int d = n - 1, s = 0;
while(d % 2) { d /= 2; ++s; }
for(int a : rab_prime_mr_as) {
if(n <= a) return true;
if(pow_mod(a, d, n) == 1) continue;
times(s, r) {
/* d<= 0);
VB ret(n + 1, true);
ret[0] = false;
if(n == 0) { return ret; }
ret[1] = false;
for(int i = 2; i * i < n; ++i) if(ret[i]) {
for(int j = i * 2; j < n; j += i) { ret[j] = false; }
}
return ret;
}
/*-
verification: ok
https://atcoder.jp/contests/arc004/submissions/4016291
*/
HII prime_factor(int n) {
HII ret;
if(n <= 1) { return ret; }
#define rab_prime_factor_loop_body(x) \
while(n % (x) == 0) { ++ret[(x)]; n /= (x); }
rab_prime_factor_loop_body(2);
rab_prime_factor_loop_body(3);
for(int i = 5; i * i <= n; i += 6) {
rab_prime_factor_loop_body(i);
rab_prime_factor_loop_body(i + 2);
}
if(n > 1) ++ret[n];
return ret;
}
/* */
void solve() {
// NN(X)
/* */
int N;cin>>N;VI X(N);times(N,Ri_0){cin>>X[Ri_0];}
/* */
times(N, i) cout << X[i] sp << (int)is_prime(X[i]) ln;
}
/* */