using System; using static System.Console; class Program { static void Main() { SetOut(new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false }); var n = FastIO.Long(); for (int i = 0; i < n; i++) { var x = (ulong)FastIO.Long(); WriteLine(x.ToString() + " " + (MillerRabin(x) ? "1" : "0")); } Out.Flush(); } public static ulong[] b64 = new ulong[] { 2, 325, 9375, 28178, 450775, 9780504, 1795265022 }; public static bool MillerRabin(ulong n) { if (n == 2) return true; if ((n & 1) == 0 || n < 2) return false; var n1 = n - 1; var s = System.Numerics.BitOperations.TrailingZeroCount(n1); var d = n1 >> s; foreach (var b in b64) { var a = b; if (a >= n) { a %= n; if (a == 0) continue; } var x = ModPow(a, d, n); if (x == 1) continue; for (int i = 0; x != n1; i++) { if (i == s - 1) return false; x = ModMul(x, x, n); } } return true; } static ulong ModPow(ulong x, ulong n, ulong mod) { var res = 1ul; while (n != 0) { if ((n & 1) == 1) res = ModMul(res, x, mod); x = ModMul(x, x, mod); n >>= 1; } return res; } static ulong ModMul(ulong l, ulong r, ulong mod) { unchecked { if (mod <= uint.MaxValue) return l % mod * (r % mod) % mod; var high = Math.BigMul(l, r, out var low) % mod; if (high == 0ul) return low % mod; var lzc = 0; if (0 <= (long)mod) { lzc = System.Numerics.BitOperations.LeadingZeroCount(mod); mod <<= lzc; high = (high << lzc) | (low >> (64 - lzc)); low <<= lzc; } var mh = mod >> 32; var ml = (ulong)(uint)mod; var q = high / mh; var p = q * ml; high -= q * mh; high = (high << 32) | (low >> 32); if (high < p) { high += mod; if (high >= mod && high < p) { high += mod; } } high -= p; q = high / mh; p = q * ml; high -= q * mh; high = (high << 32) | (uint)low; if (high < p) { high += mod; if (high >= mod && high < p) { high += mod; } } return (high - p) >> lzc; } } } public static class FastIO { static System.IO.Stream str = System.Console.OpenStandardInput(); const int size = 1024; static byte[] buffer = new byte[size]; static int ptr = size; static byte Read() { if (ptr == size) { str.Read(buffer, 0, size); ptr = 0; } return buffer[ptr++]; } public static long Long() { var c = Read(); while (c < 0x21) { c = Read(); } var n = false; if (c == '-') { n = true; c = Read(); } var ret = 0L; while (c > 0x20) { ret = ret * 10 + c - '0'; c = Read(); } return n ? -ret : ret; } }