// Arup Guha
// 7/24/2014
// Solution to 2014 SI@UCF Contest Problem: Triple Threat

import java.util.*;

public class triple {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Go through each case.
		for (int loop=0; loop<numCases; loop++)
			System.out.println(solve(stdin.nextInt()));
	}

	public static int solve(int n) {

		ArrayList<Integer> list = new ArrayList<Integer>();

		// Look for each unique prime factor.
		int div = 2;
		while (n > 1) {

			// Found one; add it once and divide out all copies.
			if (n%div == 0) {
				list.add(div);
				while (n%div == 0) n /= div;
			}
			div++;
		}

		// Fail case.
		if (list.size() < 3) return -1;

		// Ta da!
		int max = list.size();
		return list.get(max-1)*list.get(max-2)*list.get(max-3);
	}
}