import random import sys def is_prime(n): if n == 2: return 1 if n == 1 or not n % 2: return 0 d = (n - 1) >> 1 while not d % 2: d >>= 1 for _ in [0] * 20: a = random.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 <<= 1 if y != n - 1 and not t % 2: return 0 return 1 def main(): # sys.setrecursionlimit(100000) input = lambda: sys.stdin.readline()[:-1] N = int(input()) for _ in [0] * N: X = int(input()) ans = is_prime(X) print(X, ans) if not __debug__: f = open(sys.argv[1], "r") sys.stdin = f # try: # sys.set_int_max_str_digits(100000) # except AttributeError: # pass main()