from random import randrange def odd(n): while n % 2 == 0: n //= 2 return n def prime(n): if n == 1: return False if n == 2: return True if n == 3: return True for i in range(1000): a = randrange(2, n - 1) if pow(a, n - 1, n) != 1: return False prev = pow(a, odd(n - 1), n) if prev == 1: continue while prev * prev % n != 1: prev *= prev prev %= n if prev != n - 1: return False return True n = int(input()) for i in range(n): x = int(input()) if prime(x): print(x, 1) else: print(x, 0)