#include using namespace std; using ll=long long; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} void Solve(){ ll N; cin>>N; if(N==0){ cout<<0<<"\n"; return; } int B=-1; for(int i=60;i>=0;i--){ if(N>>i&1){ B=i; break; } } assert(B!=-1); ll L=0,R=0; for(int i=0;i<=B/2;i++){ R^=1LL<>i&1){ L^=1LL< ll { ll l=0,r=(ll)sqrt(x)+10; while(r-l>1){ ll mid=(l+r)/2; if(mid*mid<=x)l=mid; else r=mid; } return l; }; ll sl=find_sq(L),sr=find_sq(R); for(ll m=sl;m<=sr+1;m++){ if(m*m<=(N^m)&&(N^m)<(m+1)*(m+1)){ cout<<(N^m)<<"\n"; return; } } cout<<-1<<"\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin>>T; while(T--){ Solve(); } }