#pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx") #include using namespace std; using ull = unsigned long long; using ld = long double; using ll = long long; #define mod 1000000007ll #define loop(i, n) for (int i = 0; i < n; i++) #define flagcount(bit) __builtin_popcount(bit) #define flag(x) (1ll << x) #define flagadd(bit, x) bit |= flag(x) #define flagpop(bit, x) bit &= ~flag(x) #define flagon(bit, i) bit &flag(i) #define flagoff(bit, i) !(bit & (1ll << i)) #define all(v) v.begin(), v.end() #define putout(a) cout << a << '\n' template bool chmax(T &a, const T &b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; // aをbで更新 return true; } return false; } void AS(ll X, ll L, ll R) { assert(L <= X && X <= R); } template bool primejudge(T n) { if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; double sqrtn = sqrt(n); for (T i = 3; i < sqrtn + 1; i++) { if (n % i == 0) { return false; } i++; } return true; } //modかけ算 inline ull modd(ull a, ull m) { return (a % m + m) % m; } inline ull mul(ull a, ull b, ull p) { ll ret = a * b - p * (ull)((ld)(a) * (ld)(b) / (ld)(p)); return modd(ret, p); } //modpow ull modp(ull a, ull n, ull p) { ull res = 1; while (n > 0) { if (n & 1) res = mul(res, a, p); a = mul(a, a, p); n >>= 1ll; } return res; } //素数ならtrue,合成数ならfalseを返す bool MR(ull X) { if (X < 10000) return primejudge(X); if (X % 2 == 0) return false; ull Z = X - 1; ull s = 0, t = 0; while (Z % 2 == 0) { s++; Z /= 2; } t = Z; vector A = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}; for (auto a : A) { bool ok = true; if (modp(a, t, X) == 1) { ok = false; continue; } ll Z = modp(a, t, X); for (ull i = 0; i < s; i++) { if (Z == X - 1) { ok = false; break; } Z %= X; Z = mul(Z, Z, X); } if (ok) { return false; //条件を満たすものが存在しなかった } } return true; } int main() { ll Q; cin >> Q; loop(i, Q) { ll X; cin >> X; if (MR(X)) cout << X << " " << 1 << '\n'; else cout << X << " " << 0 << '\n'; } return 0; }