def one_str(): return input() def many_int(): return list(map(int, input().split())) import random def Miller_Rabin_test(num): if num == 2: return True if num > 2 and num & 1 == 0: return False s, t = 0, num-1 while t & 1 == 0: s, t = s+1, t >> 1 a = random.randint(1, num-1) if pow(a, t, num) == 1: return True for i in range(0, s): if pow(a, pow(2, i) * t, num) == num-1: return True return False input_count = 0 N = int(input()) for i in range(N): num = int(input()) if num == 1: print(*[1,0]) else: check = Miller_Rabin_test(num) ch = 1 if check else 0 print(*[num, ch])