def miller_rabin(n): if n in [2, 3, 5, 7, 11, 13, 17]: return True d = n - 1 d = d // (d & -d) L = ( [2, 7, 61] if n < 341550071728321 else [2, 3, 5, 7, 11, 13, 17] if n <= 18446744073709551615 else [2, 325, 9375, 28178, 450775, 9780504, 1795265022] ) 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 False t <<= 1 return True n = int(input()) for i in range(n): a = int(input()) b = 0 if miller_rabin(a): b = 1 print(a, b)