#include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
long long int divSum(long long int num) {
  int result = 0;
  for (int i = 2; i <= sqrt(num); i++) {
    if (num % i == 0) {
      if (i == (num / i))
        result += i;
      else
        result += (i + num / i);
    }
  }
  return (result + 1 + num);
}
void solve() {
  long long int n;
  cin >> n;
  if (find(v.begin(), v.end(), n) == v.end()) {
    cout << -1 << endl;
  } else {
    for (long long int i = 0; i < v.size(); i++) {
      if (v[i] == n) {
        cout << i + 1 << endl;
        return;
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int t = 1;
  cin >> t;
  v.push_back(1);
  for (long long int i = 2; i <= 10005; i++) {
    v.push_back(divSum(i));
  }
  for (long long int dd = 1; dd <= t; dd++) {
    solve();
  }
}
