import sys
input = sys.stdin.readline
#Returns set prime factors O(nloglogn) (Pre-computation),log n per query
import math as mt
MAXN = 10000000+101
spf = [0 for i in range(MAXN)]

def sieve():
    spf[1] = 1
    for i in range(2, MAXN):
        spf[i] = i

    for i in range(4, MAXN, 2):
        spf[i] = 2

    for i in range(3, mt.ceil(mt.sqrt(MAXN))):
        if (spf[i] == i):
            for j in range(i * i, MAXN, i):
                if (spf[j] == j):
                    spf[j] = i

def getFactorization(x):
    ret = []
    while (x != 1):
        ret.append(spf[x])
        x = x // spf[x]

    return ret

sieve()

def getGpSum(start,ratio,terms):
    return ((start)*((ratio**terms)-1))//(ratio-1)


d = {1:1}
for i in range(2,(10**6)+1):
    p = getFactorization(i)
    e = {}
    for j in p:
        if j in e:
            e[j] += 1

        else:
            e[j] = 1

    ans = 1
    for j in e:
        prod = getGpSum(1,j,e[j]+1)
        ans = ans*prod

    if ans in d:
        continue

    d[ans] = i

# p = getFactorization(18)
# e = {}
# for j in p:
#     if j in e:
#         e[j] += 1
#
#     else:
#         e[j] = 1

# print(e)
# print(d)
for _ in range(int(input())):
    c = int(input())
    if c in d:
        sys.stdout.write(str(d[c])+"\n")

    else:
        sys.stdout.write("-1" + "\n")