#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int T; cin >> T; while(T--){ int N; cin >> N; int bcnt = __builtin_popcount(N); if(bcnt == 1){ cout << "-1\n"; }else{ bool flg = true; int ans = 0; for(int j = 0; j < 30; j++){ if(N >> j & 1){ if(flg){ ans |= 1 << j; flg = false; }else{ break; } } if(!flg){ ans |= 1 << j; } } cout << ans << '\n'; } } }