#include using namespace std; typedef long long ll; int main() { int N; cin >> N; ll p[N]; for (int i = 0; i < N; i++) { cin >> p[i]; } ll v = 2; ll t = pow(10, 18); for (int i = 0; i < N; i++) { v = 2; bool flag = true; for (ll x = 1; x < 1000; x++) { if (v > t) break; if ((v % p[i]) == (x % p[i])) { flag = false; cout << x << "\n"; break; } v *= 2; v %= p[i]; } if (flag) { cout << "-1\n"; } } return 0; }