import random from sys import stdin, stdout def main(): N = int(input()) X = map(int, stdin.read().splitlines()) for i in X: stdout.write(str(i) + ' ' + is_prime(i) + '\n') 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 k in range(40): 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' input = lambda: stdin.readline() main()