#include <bits/stdc++.h>
using namespace std;
vector<int> d(500);
unsigned long sum(unsigned long a) {
  unsigned long sum = 1, k = 1, i;
  if (a == 1) return a;
  while ((a & 1) == 0) {
    k <<= 1;
    a >>= 1;
  }
  k = (k << 1) - 1;
  if (a == 1)
    return k;
  else
    sum = k;
  for (i = 3; i * i <= a; i += 2) {
    k = 1;
    while (a % i == 0) {
      k *= i;
      a /= i;
    }
    if (k > 1) sum *= ((k * i) - 1) / (i - 1);
  }
  if (a > 1) sum *= a + 1;
  return sum;
}
void solve() {
  int n;
  cin >> n;
  for (int i = 1; i < 500; i++) {
    if (d[i] == n) {
      cout << i << "\n";
      return;
    }
  }
  cout << "-1"
       << "\n";
  return;
}
int main() {
  int t;
  cin >> t;
  for (int i = 1; i < 500; i++) {
    d[i] = sum(i);
  }
  while (t--) {
    solve();
  }
  return 0;
}
