def isPrimeMR(n): d = n - 1 d = d // (d & -d) L = [1234577] for a in L: t = d y = pow(a, t, n) if y == 1: continue while y != n - 1: y = y * y % n if y == 1 or t == n - 1: return 0 t <<= 1 return 1 P = [2, 3, 5, 7, 11, 13, 17, 19] setP = set(P) def isPrime(n): if n in setP: return 1 if n < 20: return 0 return isPrimeMR(n) N = int(input()) for _ in range(N): n = int(input()) print(n, isPrime(n))