def isPrimeMR(n): d = n - 1 d = d // (d & -d) L = [2, 7, 61] if n < 1<<32 else [2, 3, 5, 7, 11, 13, 17] if n < 1<<48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] 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 for p in P: if n % p == 0: return 0 return isPrimeMR(n) N = int(input()) for _ in range(N): n = int(input()) print(n, isPrime(n))