#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define eps 1e-8
#define pb push_back
#define fi first
#define se second
#define SZ(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define db1(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << #x << " = " << x << " " << #y << " = " << y << endl
#define gg cout << "---------QAQ--------\n"
#define MEM(a, b) memset(a, b, sizeof(a))

using namespace std;
typedef unsigned long long ull;
typedef long double ld;
typedef long long ll;
const int N = 1e7 + 10, M = 5100;
const int mod = 1e9 + 7;

int n, l, r, s;
int g[N], f[N], v[N], p[N];
int mi[N];
void pre() {
    int tot = 0;
  g[1] = f[1] = 1;
  n = N-2;
  for (int i = 2; i <= n; ++i) {
    if (!v[i]) v[i] = 1, p[++tot] = i, g[i] = i + 1, f[i] = i + 1;
    for (int j = 1; j <= tot && i <= n / p[j]; ++j) {
      v[p[j] * i] = 1;
      if (i % p[j] == 0) {
        g[i * p[j]] = g[i] * p[j] + 1;
        f[i * p[j]] = f[i] / g[i] * g[i * p[j]];
        break;
      } else {
        f[i * p[j]] = f[i] * f[p[j]];
        g[i * p[j]] = 1 + p[j];
      }
    }
  }
  //for (int i = 1; i <= n; ++i) f[i] = (f[i - 1] + f[i]);
  MEM(mi, 0x3f);
  for(int i = 1; i <= n; ++i)
  {
      if(f[i] > 10000000) continue;
        mi[f[i]] = min(mi[f[i]], i);
  }
}

void sol()
{
    scanf("%d", &n);
    if(mi[n] == INF) puts("-1");
    else printf("%d\n", mi[n]);
}
int main()
{
    pre();
    int _; scanf("%d", &_);  while (_--)
    sol();
    return 0;
}
/*

*/