# N≦2^64 def is_prime(N: int): if N <= 1: return False if N == 2: return True if N % 2 == 0: return False s = 0 d = N - 1 while d % 2 == 0: s += 1 d >>= 1 for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: if a % N == 0: return True x = pow(a, d, N) if x != 1: t = 0 while t < s and x < N - 1: t += 1 x = x * x % N if t == s: return False return True for _ in range(int(input())): n = int(input()) print(n, is_prime(n) | 0)