import java.util.Scanner;

public class CodeForces_Short_task {
public static void main(String args[]) {
	Scanner sc= new Scanner(System.in);
	int t= sc.nextInt();
	for(int i=0;i<t;i++) {
		int num = sc.nextInt();
		int n=1;
		int count=0;
		for(int j=1;j<=num;j++) {
			if(count<=num) {
				count=findNo(j);
				if(count==num) {
					n=j;
					break;
				}
			}else {
				n=-1;
				break;
			}
			
		}
		System.out.println(n);

	}
}
public static int findNo(int n) {
	int count=0;
	for(int i=1;i<=n;i++) {
		if(n%i==0) {
			count+=i;
		}
	}
	//System.out.println(n+" "+count);
	return count;
}

}
