#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; void solve (int p) { int cur = 2 % p; int cnt = 1; int res = -1; while (res == -1) { if (cur == cnt % p) res = cnt; cur *= 2; cur %= p; cnt++; } //cout << "ans "; cout << res << endl; } int main() { int n; cin >> n; while (n--) { int p; cin >> p; solve(p); } return 0; }