import random from collections import defaultdict import sys INF = 1 << 64 def check_composite(n, a, d, s): x = pow(a, d, n) if x == 1 or x == n - 1: return False for r in range(1, s): x = x * x % n if (x == n - 1): return False return True def MillerRabin(n, itr=10): """ Primality tests by MillerRabin in O(1). """ if n < 4: return (n == 2 or n == 3) s, d = 0, n - 1 while (d & 1 == 0): d >>= 1 s += 1 for _ in range(itr): a = 2 + random.randint(1, INF) % (n - 3) if check_composite(n, a, d, s): return False return True def input(): return sys.stdin.readline().rstrip() MAXN = 100010 C = [i ** 2 + 1 for i in range(MAXN + 1)] def main(): """ verify submission """ Q = int(input()) Query = [int(input()) for i in range(Q)] d = {i: defaultdict(int) for i in range(MAXN + 1)} for i in range(1, MAXN + 1): if C[i] == 1: continue p = C[i] for j in range(i, MAXN + 1, p): while C[j] % p == 0: C[j] //= p d[j][p] += 1 for j in range(p - i, MAXN + 1, p): while C[j] % p == 0: C[j] //= p d[j][p] += 1 for idx in Query: fact = [] v = 1 for key, value in d[idx].items(): assert MillerRabin(key, itr=5) == True for _ in range(value): fact.append(key) v *= pow(key, value) assert v == idx * idx + 1 fact.sort() print(*fact) return 0 if __name__ == "__main__": main()