# -*- coding: utf-8 -*-
"""
Created on Sat Apr 10 23:59:51 2021

@author: sumanthsetty
"""
import math

def sumofdiv(j,n):
    s = 0
    for k in range(1,int(math.sqrt(j))+1):
            
        if j%k==0:
            s+=k
            if(k!=j//k):
                s+=j//k
                
    if s == n:
        return 1
    
    return 0
    

for i in range(int(input())):
    
    n = int(input())
    flag = 0
    
    if 1==n:
        print(1)
        continue
    
    for j in range(2,(n//2)+2):
        
        if sumofdiv(j,n):
            print(j)
            flag = 1
    
    if flag==0:
        print(-1)
        
        
            