#include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int N; cin >> N; if(__popcount(N) == 1){cout << "-1\n"; continue;} int n = N,answer = N; while(true){ answer += answer&-answer; if(__popcount(answer) < __popcount(N)) break; } cout << answer-N << "\n"; } }