#include<bits/stdc++.h>
using namespace std;
#define LL unsigned long long int
int bts[10000000];
int pop(unsigned x)
{
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
x = (x + (x >> 4)) & 0x0F0F0F0F;
x = x + (x >> 8);
x = x + (x >> 16);
return x & 0x0000003F;
}
void init()
{
bts[0]=0;
for(int i=1;i<10000000;i++)
{
bts[i]=bts[i-1]+pop(i);
}
}
int Lmb(LL n)
{
int bits=0;
while(n > 1)
{
n>>=1;
bits+=1;
}
return bits;
}
LL Total_Bits(LL n)
{
//cout<<"calling total bits"<<" ";
if(n==0) return 0;
LL m = Lmb(n);
if(n==(pow(2,(m+1))-1))
return 1LL*(m+1)*pow(2,m);
n = n - pow(2,m);
return (n+1) + Total_Bits(n) + m*pow(2,(m-1));
}
LL search(LL H, int L, LL n)
{
LL M=0,c=0;
while(L<=H)
{
M=(H+L)/2;
if(M < 10000000) c = bts[M];
else
{c = Total_Bits(M);}
if(c==n)
return M;
else if(c < n)
L=M+1;
else if(c > M)
H = M-1;
}
return M;
}
int main()
{
LL n,m,a;
int tc;init();
scanf("%d",&tc);
while(tc--)
{
scanf("%lld",&n);
m = n;
a = search(n,0,n);
if(m==Total_Bits(a))
printf("%lld\n",a);
else
printf("Does Not Exist\n");
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBMTCB1bnNpZ25lZCBsb25nIGxvbmcgaW50CmludCBidHNbMTAwMDAwMDBdOwppbnQgcG9wKHVuc2lnbmVkIHgpCnsKICAgIHggPSB4IC0gKCh4ID4+IDEpICYgMHg1NTU1NTU1NSk7CiAgICB4ID0gKHggJiAweDMzMzMzMzMzKSArICgoeCA+PiAyKSAmIDB4MzMzMzMzMzMpOwogICAgeCA9ICh4ICsgKHggPj4gNCkpICYgMHgwRjBGMEYwRjsKICAgIHggPSB4ICsgKHggPj4gOCk7CiAgICB4ID0geCArIC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