#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } long long pow_mod(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n % 2 == 1) { res = res * a % mod; } a = a * a % mod; n /= 2; } return res; } int main() { fast_io(); int t; cin >> t; for (; t--;) { long long n; cin >> n; vector pf; long long n_tmp = 2 * n - 1; for (long long i = 2; i * i <= n_tmp; i++) { while (n_tmp % i == 0) { pf.push_back(i); n_tmp /= i; } } if (n_tmp > 1) { pf.push_back(n_tmp); } long long phi = 2 * n - 1; for (long long p : pf) { phi = phi / p * (p - 1); } vector fac; for (long long i = 1; i * i <= phi; i++) { if (phi % i == 0) { fac.push_back(i); if (i * i != phi) { fac.push_back(phi / i); } } } long long ans = phi; for (long long a : fac) { if (pow_mod(2, a, 2 * n - 1) == 1) { ans = min(ans, a); } } cout << ans << "\n"; } }