def isprime(n): if n == 1: return False aa = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] for a in aa: if n == a: return True if n % a == 0: return False d, s = n - 1, 0 while d % 2 == 0: d >>= 1 s += 1 for a in aa: a0 = pow(a, d, n) if a0 == 1 or a0 == n - 1: continue for r in range(1, s): a0 = a0 * a0 % n if a0 == n - 1: break else: return False return True t = int(input()) for _ in range(t): x = int(input()) print(x, 1 if isprime(x) else 0)