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