def miller_rabin(n): if n < 2: return False for p in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]: if n < p * p: return True if n % p == 0: return False s, d = 0, n - 1 while d & 1 == 0: s, d = s + 1, d >> 1 # n = (2 ** s) * d for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: x = pow(a, d, n) if x in (1, n - 1): continue for _ in range(s - 1): x = (x * x) % n if x == n - 1: break else: return False return True n = int(input()) for i in range(n): a = int(input()) b = 0 if miller_rabin(a): b = 1 print(a, b)