def miller_rabin(n: int): if n == 2: return True if n < 2 or (n & 1) == 0: return False n1 = n - 1 d = n1 s = 0 while (d & 1) == 0: d //= 2 s += 1 for a in [2,325,9375,28178,450775,9780504,1795265022]: if a % n == 0: continue t = pow(a, d, n) # = pow(a, d) % n if t == 1 or t == n1: continue for _ in range(s - 1): t = pow(t, 2, n) # = pow(t, 2) % n if t == n1: break else: # breakでループを抜けなかった時 return False return True n = int(input()) for _ in range(n): x = int(input()) print(x, 1 if miller_rabin(x) else 0)