#include using namespace std; using ll = long long; ll phi(ll n) { ll res = n; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { res = res / i * (i - 1); while (n % i == 0) n /= i; } } if (n > 1) res = res / n * (n - 1); return res; } ll modpow(ll a, ll n, ll mod) { ll p = a, res = 1; while (n) { if (n & 1) res = res * p % mod; p = p * p % mod; n >>= 1; } return res; } void solve() { ll k; cin >> k; if(k == 1) { cout << 1 << "\n"; return; } ll m = 2 * k - 1; ll pm = phi(m); ll ans = 4e18; for (ll i = 1; i * i <= pm; i++) { if (pm % i != 0) continue; if (modpow(2, i, m) == 1) ans = min(ans, i); if (modpow(2, pm / i, m) == 1) ans = min(ans, pm / i); } cout << ans << "\n"; } int main() { int q; cin >> q; for (int i = 0; i < q; i++) solve(); }