# https://codeforces.com/contest/1512/problem/G
import math

def getDivisors(n):
    div = []
    i = 1
    while i <= math.sqrt(n):
        if n % i == 0:
            if n / i == i:
                div.append(i)
            else:
                div.append(i)
                div.append(int(n/i))
        i += 1
    div.sort()
    return div

def main():
    t = int(input())
    cases = [int(input()) for i in range(t)]

    for n in cases:
        dList = []
        i = 1
        while i < n:
            if sum(getDivisors(i)) <= n:
                dList.append(i)
            i += 1
        
        for i in dList:
            if sum(getDivisors(i)) == n:
                print(i)
                break
        else:
            print(-1)
            
            
if __name__ == '__main__':
    main()