1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 using namespace std;
7
8 int mymax(int x,int y) {return x>y?x:y;}
9
10 struct hugeint
11 {
12 int a[110],l;
13 void clear()
14 {
15 memset(a,0,sizeof(a));
16 l=1;
17 }
18 friend hugeint operator + (hugeint x,hugeint y)
19 {
20 int ll=mymax(x.l,y.l);
21 for(int i=1;i<=ll;i++) x.a[i]=x.a[i]+y.a[i];
22 for(int i=1;i<=ll;i++) x.a[i+1]+=x.a[i]/10,x.a[i]%=10;
23 while(x.a[ll+1]!=0) x.a[ll+2]+=x.a[ll+1]/10,x.a[ll+1]%=10,ll++;
24 x.l=ll;
25 return x;
26 }
27 friend hugeint operator + (hugeint x,int y)
28 {
29 int ll=x.l; x.a[1]+=y;
30 for(int i=1;i<=ll;i++) x.a[i+1]+=x.a[i]/10,x.a[i]%=10;
31 while(x.a[ll+1]!=0) x.a[ll+2]+=x.a[ll+1]/10,x.a[ll+1]%=10,ll++;
32 x.l=ll;
33 return x;
34 }
35 friend hugeint operator / (hugeint x,int y)
36 {
37 int nw=0;
38 for(int i=x.l;i>=1;i--)
39 {
40 nw=nw*10+x.a[i];
41 x.a[i]=nw/y;
42 nw%=y;
43 }
44 while(x.a[x.l]==0&&x.l>1) x.l--;
45 return x;
46 }
47 };
48
49 hugeint k1,k2;
50 void dfs(hugeint xx)
51 {
52 if(xx.l==1&&xx.a[1]==1)
53 {
54 k1=xx;k2.clear();
55 return;
56 }
57 dfs((xx+1)/2);
58 if(xx.a[1]&1) k1=k1+k2;
59 else k2=k1+k2;
60 }
61
62 char s[110];
63
64 int main()
65 {
66 int T;
67 scanf("%d",&T);
68 while(T--)
69 {
70 scanf("%s",s+1);
71 int l=strlen(s+1);
72 hugeint xx;xx.clear();
73 for(int i=1;i<=l;i++) xx.a[l-i+1]=s[i]-‘0‘;
74 xx.l=l;
75 dfs(xx);
76 for(int i=k1.l;i>=1;i--) printf("%d",k1.a[i]);
77 printf("\n");
78 }
79 return 0;
80 }