def Miller(N): v = [2, 7, 61] if N < 4_759_123_141 else [2, 3, 5, 7, 11, 13, 17] if N < 341_550_071_728_321 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] if N < 2: return 0 if N in v: return 1 d = N - 1 s = 0 while d & 1 == 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))