#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int T;
struct Cbig
{
int a[110],len;
int & operator [] (int b) {return a[b];}
Cbig() {memset(a,0,sizeof(a)),len=1;}
Cbig div2()
{
Cbig b;
b.len=len;
for(int i=len;i>=1;i--) b[i]+=a[i],b[i-1]=(b[i]&1)*10,b[i]>>=1;
while(b.len>1&&!b[b.len]) b.len--;
return b;
}
Cbig dec()
{
Cbig b;
memcpy(b.a,a,sizeof(a)),b.len=len;
b[1]--;
for(int i=1;i<=len;i++) if(b[i]<0) b[i]+=10,b[i+1]--;
while(b.len>1&&!b[b.len]) b.len--;
return b;
}
Cbig inc()
{
Cbig b;
memcpy(b.a,a,sizeof(a)),b.len=len;
b[1]++;
for(int i=1;i<=len;i++) b[i+1]+=b[i]/10,b[i]%=10;
while(b[b.len+1]) b.len++;
return b;
}
Cbig operator + (Cbig b) const
{
Cbig c;
c.len=max(len,b.len);
for(int i=1;i<=c.len;i++) c[i]+=a[i]+b[i],c[i+1]+=c[i]/10,c[i]%=10;
while(c[c.len+1]) c.len++;
return c;
}
void print()
{
for(int i=len;i>=1;i--) printf("%d",a[i]);
printf("\n");
return ;
}
}A,B,X,Y;
int n;
char str[110];
void work()
{
scanf("%s",str),n=strlen(str);
int i;
A=B=X=Y=Cbig();
A.len=n;
for(i=0;i<n;i++) A[n-i]=str[i]-‘0‘;
if(A.len==1&&A[1]==0) {printf("0\n"); return ;}
if(A.len==1&&A[1]==1) {printf("1\n"); return ;}
while(!(A[1]&1)) A=A.div2();
if(A.len==1&&A[1]==1) {printf("1\n"); return ;}
B=A.inc(),A=A.dec(),A=A.div2(),B=B.div2(),X[1]=Y[1]=1;
while(1)
{
if(A[1]&1) Y=Y+X,A=A.dec(),A=A.div2(),B=B.div2();
else X=X+Y,B=B.inc(),A=A.div2(),B=B.div2();
if(A.len==1&&A[1]==0) break;
}
Y.print();
}
int main()
{
scanf("%d",&T);
while(T--) work();
return 0;
}//3 1 3 10