#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define pii pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pii>
#define vvi vector<vector<int>>
#define P_B push_back
#define M_P make_pair
#define endl "\n"

#define MOD 1000000007
#define pi 3.141592653589793238


// void file_io()
// {
//     freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
// }


const int N = 1e7 + 5;

vi min_factor(N, -1);
vi answer(N, -1);
vi sum(N, -1);


void primeFactorize() {

	min_factor[1] = 1;
	sum[1] = 1;

	for (int i = 2; i*i < N; i++) {

		if(min_factor[i] != -1) continue;
		min_factor[i] = i;
		for (int j = i*i; j < N; j += i) {
			if(min_factor[j] != -1) continue;
			min_factor[j] = i;
		}
	}

	for (int i = 2; i < N; i++) {

		if(min_factor[i] == -1) {

			sum[i] = i+1;
			min_factor[i] = i;

		} else {

			int x = i;
			sum[i] = 1;
			while(x%min_factor[i] == 0) {

				sum[i] = sum[i]*min_factor[i] + 1;
				x /= min_factor[i]; 
			}

			sum[i] = sum[i]*sum[x];

		}
	}


	for (int i = N-1; i >= 1; i--) {

		if(sum[i] < N) answer[sum[i]] = i;
	}
		
}

int32_t main() {
    
    // file_io();
    
    primeFactorize();

    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);


    int T; cin>>T; while(T--) 
    {
        
    	int n;
    	cin >> n;

    	cout << answer[n] << endl;

    }    
    
    return 0;
}   
