import java.util.*;
import java.io.*;

public class tr0 {
	static PrintWriter out;
	static StringBuilder sb;
	static long mod = (long) 1e9 + 7;
	static long inf = (long) 1e16;
	static int n, m, k;
	static ArrayList<Integer>[] ad;
	static int[][] remove, add;
	static int[][] memo, memo1[];
	static boolean vis[];
	static long[] inv, ncr[];
	static HashMap<Integer, Integer> hm;
	static int[] pre, suf, Smax[], Smin[];
	static int idmax, idmin;
	static ArrayList<Integer> av;
	static HashMap<Integer, Integer> mm;
	static boolean[] msks;
	static int[] lazy[], lazyCount;
	static int[] dist;
	static char[][] g;
	static int ave;
	static ArrayList<Integer> gl;
	static int[] a, d, q;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int t = sc.nextInt();
		seive(10000002);
		int[] f = new int[10000001];
		Arrays.fill(f, Integer.MAX_VALUE);
		for (int i = 2; i <= 10000000; i++) {
			if (si[i] != i)
				continue;
			long sum = 0;
			long p = 1;
			sum += p;
			while (sum <= 10000000) {
				f[(int) sum] = Math.min(f[(int) sum], (int) p);
				p = p * i;
				sum += p;
			}
		}
		long[] dp = new long[f.length];
		Arrays.fill(dp, 1);
		for (int i = 0; i < f.length; i++)
			if (f[i] == Integer.MAX_VALUE)
				dp[i] = 0;
		for (int i = 3; i < f.length; i++) {
			dp[i] = Math.min(f[i], f[si[i]] * dp[i / si[i]]);
		}

		while (t-- > 0) {
			int c = sc.nextInt();
			long ans = f[c];
			ff = new TreeMap<>();
			factor(c);
			long tem = 1;
			for (int k : ff.keySet()) {
				int y = ff.get(k);
				if (f[y] != Integer.MAX_VALUE)
					tem *= f[y];
				else {
					tem = -1;
					break;
				}
			}
			if (ans == Integer.MAX_VALUE)
				ans = -1;
			if (ans == -1 && tem == -1)
				out.println(-1);
			else {
                  if(ans==-1)
                	  out.println(tem);
                  else if(tem==-1)
                	  out.println(ans);
                  else
                	  out.println(Math.min(ans, tem));
			}
		}
		out.flush();
	}

	static int[] si;
	static ArrayList<Integer> primes;

	static void seive(int N) {
		si = new int[N];
		primes = new ArrayList<>();
		si[1] = 1;
		for (int i = 2; i < N; i++) {
			if (si[i] == 0) {
				si[i] = i;
				primes.add(i);
			}
			for (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)
				si[primes.get(j) * i] = primes.get(j);
		}
	}

	static TreeMap<Integer, Integer> ff = new TreeMap<>();

	static void factor(int n) {
		if (si[n] == n) {
			handle(n);
			return;
		}
		handle(si[n]);
		factor(n / si[n]);
	}

	static void handle(int n) {
		ff.put(n, ff.getOrDefault(n, 1) * n);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public int[] nextArrIntSorted(int n) throws IOException {
			int[] a = new int[n];
			Integer[] a1 = new Integer[n];
			for (int i = 0; i < n; i++)
				a1[i] = nextInt();
			Arrays.sort(a1);
			for (int i = 0; i < n; i++)
				a[i] = a1[1].intValue();
			return a;
		}

		public long[] nextArrLongSorted(int n) throws IOException {
			long[] a = new long[n];
			Long[] a1 = new Long[n];
			for (int i = 0; i < n; i++)
				a1[i] = nextLong();
			Arrays.sort(a1);
			for (int i = 0; i < n; i++)
				a[i] = a1[1].longValue();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}