import java.util.*;
public class MyClass {
    public static long d(long i)
    {
        long s=0;
        for(int j=1;j<=i;j++)
        {
            if(i%j==0)
            {
                s=s+j;
            }
        }
        return s;
    }
    public static void main(String args[]) {
     Scanner sc=new Scanner(System.in);
     int t=sc.nextInt();
     long flag=0;
     while(t-->0)
     {
         long c=sc.nextLong();
         for(long i=1;i<=10000000;i++)
         {
             long x=d(i);
             if(x==c)
             {
                 flag=i;
                 break;
             }
             else if(x>c)
             {
                 flag=-1;
                 break;
             }
         }
         if(flag==-1)
         {
             System.out.println(flag);
         }
         else
         {
              System.out.println(flag);
         }
         
              }
    }
}