#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; ll phi(ll n) { ll res = n; for(ll i = 2; i*i <= n; i++) { if (n % i == 0) { res -= res / i; while(n % i == 0) n /= i; } } if (n > 1) res -= res / n; return res; } vector divisor(ll n){ vector ret; for(ll i=1; i*i<=n; i++){ if(n%i==0){ ret.push_back(i); if(i!=n/i) ret.push_back(n/i); } } sort(ALLOF(ret)); return ret; } ll mod_pow(ll x, ll n, ll mod){ ll res = 1; while(n>0){ if(n&1) res = res*x%mod; x = x*x%mod; n >>= 1; } return res; } ll solve(ll N){ if(N == 1) return 1; vector d = divisor(phi(2*N-1)); rep(i,d.size()){ ll x = d[i]; if(mod_pow(2,x,2*N-1) == 1) return x; } return -1; } int main(){ int T; cin >> T; rep(t,T){ ll N; cin >> N; cout << solve(N) << endl; } return 0; }