import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		for(int i =1;i<=n;i++) {
			boolean flag=true;
			int x = scn.nextInt();
			for(int j=x/2-1;j<=x;j++) {
				if(sum(j)==x) {
					System.out.println(j);
					flag=false;
					break;
				}
			}
			if(flag==true) {
				System.out.println(-1);
			}
				
			}
		}
public static int sum(int n) {
		int s=0;
		for(int i=1;i<=Math.sqrt(n);i++) {
			
			if(n%i==0) {
				s=s+i;
			}
			
		}
		return s+n;
	}
}