#include <bits/stdc++.h>
using namespace std;
int test;
int c;
const int maxn = 1e7 + 10;
long long nums[maxn];
void pre() {
  long long index;
  for (long long i = 1; i < maxn; i++) {
    for (long long u = i; u < maxn; u++) {
      index = i * u;
      if (index < maxn) {
        nums[index] += (i + u);
        if (i == u) nums[index] -= u;
      } else
        break;
    }
  }
}
void solve() {
  int index = 1;
  int total = 0;
  for (index = 1; index <= c && total < 10; index++)
    if (nums[index] == c)
      break;
    else if (nums[index] > c)
      total++;
  if (nums[index] != c)
    cout << "-1\n";
  else
    cout << index << endl;
}
int main() {
  scanf("%d", &test);
  pre();
  while (test--) {
    scanf("%d", &c);
    solve();
  }
}
