from random import randint def miller_rabin(n, rep=100): #random.randint if n == 2: return True if n == 1 or n % 2 == 0: return False d = (n - 1) // 2 while d % 2 == 0: d //= 2 for k in range(rep): a = randint(1, n - 1) t = d y = pow(a, t, n) while t != n - 1 and y != 1 and y != n - 1: y = (y * y) % n t *= 2 if y != n - 1 and t % 2 == 0: return False return True import sys input = sys.stdin.readline N = int(input()) for _ in range(N): x = int(input()) res = int(miller_rabin(x)) print(x, res)