#include #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll phi(ll n) { ll m = n; ll ans = 1; for(ll i = 2; i * i <= n; i ++) { if(m % i == 0) { m /= i; ans *= (i - 1); } else continue; while(m % i == 0) { m /= i; ans *= i; } } if(m > 1) ans *= m - 1; return ans; } vector divisor(ll n) { vector v; for(ll i = 1; i * i <= n ; i ++) { if(n % i == 0) { if(i * i != n) v.pb(n / i); else v.pb(i); } } return v; } void solve() { ll n; cin >> n; auto v = divisor(phi(n * 2 - 1)); sort(be(v)); all(e, v) { if(modpow(2LL, e, n * 2 - 1) == 1) { cout << e << endl; return ; } } } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int t; cin >> t; while(t--) solve(); return 0; }