import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); boolean[] isNotPrime = new boolean[100002]; ArrayList primes = new ArrayList<>(); for (int i = 2; i < isNotPrime.length; i++) { if (!isNotPrime[i]) { primes.add(i); for (int j = 2; i * j < isNotPrime.length; j++) { isNotPrime[i * j] = true; } } } int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { long x = sc.nextInt(); x = x * x + 1; boolean isFirst = true; for (int y : primes) { if (y > Math.sqrt(x)) { break; } if (x % y == 0) { if (!isFirst) { sb.append(" "); } isFirst = false; sb.append(y); while (x % y == 0) { x /= y; } } } if (x > 1) { if (!isFirst) { sb.append(" "); } sb.append(x); } sb.append("\n"); } System.out.print(sb); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }