#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define req(i,n) for(int i = 1;i <= n; i++) #define rrep(i,n) for(ll i = n-1;i >= 0;i--) #define ALL(obj) begin(obj), end(obj) #define RALL(a) rbegin(a),rend(a) typedef long long ll; const ll mod = 1e9 + 7; unsigned long long mod_mul(unsigned long long a, unsigned long long b, unsigned long long M) { long long ret = a * b - M * (unsigned long long)((long double)(a) * (long double)(b) / (long double)(M)); return ret + M * (ret < 0) - M * (ret >= (ll)M); }const unsigned long long numset[] = { 2, 325, 9375, 28178, 450775, 9780504, 1795265022ULL }; unsigned long long mod_pow(unsigned long long x, unsigned long long k, unsigned long long mod) { unsigned long long res = 1; while (k) { if (k & 1) res = mod_mul(res, x, mod); x = mod_mul(x, x, mod); k >>= 1; }return res; } // check if n is prime bool check(unsigned long long n) { if (n < 2 || ((n % 6 != 1) && (n % 6 != 5))) return (n == 2) || (n == 3); unsigned long long d = n - 1, s = 0; while (d % 2 == 0) { d /= 2; s++; }for (unsigned long long a : numset) { if (a % n == 0) return 1; unsigned long long res = mod_pow(a, d, n); if (res == 1) continue; bool ok = 1; for (unsigned int r = 0; r < s; r++) { if (res == n - 1) { ok = 0;break; }res = mod_mul(res, res, n); }if (ok) return 0; }return 1; } int main() { int n; cin >> n; rep(i, n) { ll x; cin >> x; cout << x << " " << check(x) << endl; } }