#include using namespace std; int solve(int n) { constexpr int64_t sz = 50000; int64_t mod = 2 * n - 1; map v; int64_t x = 1, m = 1; v[1] = 0; for (int i = 1; i <= sz; i++) { x = 2 * x % mod; m = (mod + 1) / 2 * m % mod; if (x == 1) return i; v[x] = i; } int64_t y = 1; for (int i = 1; ; i++) { y = y * m % mod; if (v[y]) { return sz * i + v[y]; } } return -1; } int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; cout << solve(n) << endl; } }