dd=[1]*10000003
for i in range(2,int((1e7)**.5)):
    if dd[i]:
        for j in range(2*i,int(1e7)+1,i):
            dd[j]+=i
for i in range(2,int(1e7+3)):
    dd[i]+=i
d=[-1]*10000003
for i in range(1,int(1e7+3)):
    if(dd[i]<int(1e7)):
        
        if d[dd[i]]!=-1:
            d[dd[i]]=min(d[dd[i]],i)
        else:
            d[dd[i]]=i




t=int(input())
for i in range(t):
    c=int(input())
     
    print(d[c])