# v = [2, 7, 61] # # N <= 4,759,123,140 (4*10^9) # v = [2, 3, 5, 7, 11, 13, 17] # # N <= n < 341,550,071,728,321 (3*10^14) v = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] # Nが大きいとき def Miller(N): if N < 2: return 0 if N in v: return 1 d = N - 1 s = 0 while d % 2 == 0: d //= 2 s += 1 for a in v: if pow(a, d, N) != 1: ok = True for r in range(s): if pow(a, d * 1 << r, N) == N - 1: ok = 0 break if ok: return 0 return 1 import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) print(n, Miller(n))