


if __name__ == '__main__':
    tc = int(input())
    M = 10**7 // 2 +1
    A = [0]* (M+1)
    A [1] = 1
    for j in range(2,M+1):
        A [j] = 1 + j
    k = 2
    while k*k <= M :
        j = k*k
        A [j] += k
        j += k
        s = k + (k + 1)
        while j <= M:
            A [j] += s
            j += k
            s += 1
        k += 1

    myd = {}

    for i,val in enumerate(A):
        if val not in myd:
            myd[val] = i

    del A

    for cn in range(tc):
        c = int(input())
        
        if c in myd:
            print(myd[c])
        else:
            print(-1)