import java.util.*;
import java.io.*;
public class Main{
    static int findsum(int p)
    {
        if(p==1)
        {
            return 1;
        }
        if(p<1)
        {
            return 0;
        }
        int sum=1+p;
        for(int i=2;i<=p/2;i++)
        {
            if(p%i==0)
            {
                sum=sum+i;
            }
        }
        return sum;
    }
    public static void main(String args[])throws IOException
    {
        InputStreamReader ir=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(ir);
        int t=Integer.parseInt(br.readLine());
        for(int i=0;i<t;i++)
        {
            int c=Integer.parseInt(br.readLine());
            int ans=-1;
            int l=1,h=c;
            for(int j=1;j<c;j++)
            {
                if(findsum(j)==c)
                {
                    ans=j;
                    break;
                }
            }
                
            
            System.out.println(ans);
        }
    }
}