#include using namespace std; using ll = long long; bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; } bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; } int ppc(ll N) { return __builtin_popcountll(N); } void naive(ll N) { int P = ppc(N); for (int x = 0; x < 100; x++) { if (P > ppc(N + x)) { cout << x << '\n'; return; } } cout << -1 << '\n'; } void solve(ll N) { if (ppc(N) == 1) { cout << 1 << '\n'; return; } ll ans = 0; int C = 0; for (int i = 0; i < 30; i++) { if (N >> i & 1) { if (C++ == 0) ans += 1LL << i; } else { if (C) ans += 1LL << i; } if (C == 2) break; } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { ll N; cin >> N; if (N <= 4) naive(N); else solve(N); } }