#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 2000000000000000001 long long dp[2][30][30],ndp[2][30][30]; int main(){ int _t; cin>>_t; rep(_,_t){ long long N; cin>>N; //N = 1LL << 50; //vector dp(2,vector(30,vector(30,0))); rep(j,2){ rep(k,30){ rep(l,30){ dp[j][k][l] = 0; } } } dp[0][0][2] = 1; bool f = false; for(int i=59;i>=0;i--){ if((N>>i)&1){ f = true; } else if(!f)continue; rep(j,2){ rep(k,30){ rep(l,30){ ndp[j][k][l] = 0; } } } //vector ndp(2,vector(30,vector(30,0))); rep(j,2){ rep(k,min(30,60-i)){ rep(l,30){ if(dp[j][k][l]==0)continue; rep(m,2){ int nj = j,nk = 29,nl = 29; if(j==0 && ((N>>i)&1)==0 && m==1)continue; if(((N>>i)&1) && m==0)nj = 1; if(m==0){ nk = min(nk,k); nl = min(nl,l+1); nk = min(nk,l); } else{ nk = min(nk,k+1); nl = min(nl,l); nl = min(nl,k+2); } ndp[nj][nk][nl] += dp[j][k][l]; } } } } swap(dp,ndp); } long long ans = 0; rep(i,2){ rep(j,30){ rep(k,30){ //if(dp[i][j][k])cout<