#include using namespace std; using ll = long long; constexpr char newl = '\n'; template map prime_factor(T n) { map res; for (T i = 2; i * i <= n; i++) { while (n % i == 0) { ++res[i]; n /= i; } } if (n != 1) res[n] = 1; return res; } ll phi(ll n) { ll res = 1; for (ll i = 2; i * i <= n; i++) { ll foo = 1, bar = 1; while (n % i == 0) { if (foo > 1) bar *= i; foo *= i; n /= i; } if (foo > bar) res *= foo - bar; } if (n != 1) res *= n - 1; return res; } template vector divisor(T n) { vector res; for (T i = 1; i * i <= n; i++) { if (n % i == 0) { res.emplace_back(i); if (i != n / i) res.emplace_back(n / i); } } return res; } const ll MOD = 1000000007; ll modpow(ll x, ll n, ll mod = MOD) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int t; cin >> t; for (int i = 0; i < t; i++) { ll n; cin >> n; if (n == 1) { cout << 1 << newl; continue; } vector d = divisor(phi(2 * n - 1)); sort(d.begin(), d.end()); ll ans = -1; for (ll x : d) { if (modpow(2, x, 2 * n - 1) == 1) { ans = x; break; } } cout << ans << newl; } return 0; }