#include using namespace std; long long int dp[32][32][2]; long long int solve(string s,int cnt) { for(int i=0;i<=31;i++) { for(int a=0;a<=31;a++) { for(int j=0;j<2;j++) { dp[i][a][j] = 1e18; } } } dp[0][0][0] = 0; for(int i=0;i<31;i++) { for(int j=0;j<=i;j++) { for(int k=0;k<2;k++) { if(dp[i][j][k] >= 1e18) continue; int x = s[i] - '0'; x += k; int c = x/2; if(x%2==0) { dp[i+1][j][c] = min(dp[i+1][j][c],dp[i][j][k]); } else { if(j+1 <= 31) dp[i+1][j+1][c] = min(dp[i+1][j+1][c],dp[i][j][k]); } x += 1; c = x/2; if(x%2==0) { dp[i+1][j][c] = min(dp[i+1][j][c],dp[i][j][k] + (1LL << i)); } else { if(j+1 <= 31) dp[i+1][j+1][c] = min(dp[i+1][j+1][c],dp[i][j][k] + (1LL << i)); } } } } long long int res = 1e18; for(int i=0;i> tc; while(tc--) { long long int n; cin >> n; int cnt = 0; string s = ""; for(int x=0;x<31;x++) { int b = (n%2); cnt += b; s = s + (char)(b + '0'); n/=2; } long long int value = solve(s,cnt); if(value >= 1e18) cout << -1 << '\n'; else cout << value << '\n'; } return 0; }