import math
n = int(input())
for _ in range(n):
val = int(input())
for i in range(2, int(math.sqrt(val)) + 1):
if val % i == 0:
cnt = 0
while val % i == 0:
val //= i
cnt += 1
print(i, cnt) # 底数和次幂
if val == 1:
break
# 特判最后可能剩下的大于sqrt(val)的最大的质因子
if val != 1:
print(val, 1)
print()