def miller_rabin(n): if n < 2: return False if n < 9: return n == 2 or n == 3 or n == 5 or n == 7 if n % 2 == 0: return False s, d = 0, n - 1 while d & 1 == 0: s, d = s + 1, d >> 1 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)