#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
 
// For ordered tree
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;

vector<ll> v(1000001);
map<ll,vector<ll>> m;

void sumOfDivisors() {
	ll i,j;
	for(i=1;i<1000001;i++) {
		for(j=i;j<1000001;j+=i) {
			v[j] += i;
		}
	}

	for(i=0;i<1000001;i++) {
		m[v[i]].pb(i);
	}
}

void solve() {
	sumOfDivisors();
	ll t,c;
	cin >> t;
	while(t--) {
		cin >> c;
		if(m.find(c) == m.end()) cout << -1;
		else cout << m[c][0];
		cout << "\n";
	}
}

int main() { 
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	solve();
	return 0;	
}