def miller_rabin(n: int) -> bool: if n <= 2: return n == 2 if n % 2 == 0: return False s = 0 t = n - 1 while t % 2 == 0: s += 1 t //= 2 def witness_composite(a: int) -> bool: x = pow(a, t, n) if x == 1 or x == n - 1: return False for _ in range(s - 1): x = pow(x, 2, n) if x == n - 1: return False return True for a in [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]: if a >= n: break if witness_composite(a): return False return True n = int(input()) for _ in range(n): x = int(input()) print(x, int(miller_rabin(x)))