#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef unsigned long long int ll; typedef pair P; template struct SparseTable{ using F=function; const F f; const T e; vector> spt; vector vlog; SparseTable(const F f, const T &e, const vector &v):f(f), e(e){ int b=0, n=v.size(); while((1<(n)); for(int i=0; i>1]+1; } T query(int l, int r){ int b=vlog[r-l]; return f(spt[b][l], spt[b][r-(1<>n; vector a(n); for(int i=0; i>a[i]; } SparseTable seg([](ll a, ll b){ return (a|b);}, 0, a); int q; cin>>q; while(q--){ ll b; cin>>b; int k=n-1; ll x=(1ll<<60)-1; int ans=0; while(k>=0){ if((x&a[k])>0){ if(((b|a[k])&x)==b){ b^=(x&a[k]); x^=(x&a[k]); k--; }else if(((~b|a[k])&x)==(~b&x)){ ans++; b=~b&x; b^=(x&a[k]); x^=(x&a[k]); k--; }else{ ans=-1; break; } }else{ int l=-1, r=k; while(r-l>1){ int m=(l+r)/2; if((x&seg.query(m, k+1))==0) r=m; else l=m; } if(l==-1){ if(b==0) break; else if(x==b){ ans++; b=0; break; }else{ ans=-1; break; } } k=l; if(((b|a[k])&x)==b){ b^=(x&a[k]); x^=(x&a[k]); k--; }else if(((~b|a[k])&x)==~b&x){ ans++; b=~b&x; b^=(x&a[k]); x^=(x&a[k]); k--; }else{ ans=-1; break; } } } if(b!=0) ans=-1; cout<