#include using namespace std; class Prime{ using int128 = __int128_t; inline static int miller_rabin64(const int128 N) { long long M = N - 1,cnt = 0; for (; M % 2 == 0; M /= 2,cnt++); for (int128 a: {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) { if(N <= a) break; int128 r = 1; for (long long K=M; K>0; K>>=1, (a*=a) %= N) if(K&1) (r *= a) %= N; if (r == 1) continue; for (int j = 1; j < cnt && r != N - 1; j++) (r *= r) %= N; if (r != N - 1) return 0; } return 1; } inline static int miller_rabin32(const long long N) { long long M = N - 1,cnt = 0; for (; M % 2 == 0; M /= 2,cnt++); for (long long a: {2, 7, 61}) { if(N <= a) break; long long r = 1; for (long long K=M; K>0; K>>=1, (a*=a) %= N) if(K&1) (r *= a) %= N; if (r == 1) continue; for (int j = 1; j < cnt && r != N - 1; j++) (r *= r) %= N; if (r != N - 1) return 0; } return 1; } public: inline static int is_prime(long long n) { if (n <= 1) return 0; if (n == 2) return 1; if (n%2 == 0) return 0; if (n < (1LL<<32)) return miller_rabin32(n); else return miller_rabin64(n); } }; int main() { cin.tie(0);ios::sync_with_stdio(false); long long N; cin >> N; string ans = ""; for(int i = 0; i < N; ++i) { long long A; cin >> A; ans += to_string(A) + " " + to_string(Prime::is_prime(A)) + "\n"; } cout << ans; return 0; }