#include <bits/stdc++.h>
using namespace std;
long long divSum(long long num) {
  long long result = 0;
  long long x = num;
  for (long long i = 2; i <= sqrt(num); i++) {
    if (num % i == 0) {
      if (i == (num / i))
        result += i;
      else
        result += (i + num / i);
    }
  }
  return (result + 1) + x;
}
int main() {
  long long a, b, c, d, e, f, g;
  string s, s1;
  vector<long long> v, v1;
  cin >> a;
  while (a--) {
    cin >> b;
    if (b == 1) {
      cout << b << endl;
      continue;
    }
    for (c = 1; c < b; c++) {
      if (divSum(c) == b) {
        cout << c << endl;
        break;
      }
    }
    if (c == b) cout << "-1" << endl;
  }
}
