import java.util.Scanner;
public class shorttask
{
    static int divSum(int num)
    {
        
        int result = 0;
      
        for (int i = 2; i <= Math.sqrt(num); i++)
        {
            if (num % i == 0)
            {
                
                if (i == (num / i))
                    result += i;
                else
                    result += (i + num / i);
            }
        }
      
        return (result + 1+num);
    }

    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int tc=sc.nextInt();
        sc.nextLine();

        for(int j=0;j<tc;j++)
        {
            int c=sc.nextInt();
            sc.nextLine();
            int sum;
            for(int i=1;i<c;i++)
            {
                sum=divSum(i);
                if(sum==c)
                {
                    System.out.println(i);
                }
                else if(sum>c)
                {
                    System.out.println("-1");
                    break;
                }
            }
            

        }
    }
}