import sys

def solve():
    tab = list()
    maxwidth = 0
    addleft = 0
    for line in sys.stdin:
        tab.append(line.rstrip('\n'))
    for line in tab: maxwidth = max(maxwidth, len(line))
    for i in range(-1, len(tab) + 1):
        if i == -1 or i == len(tab):
            print('*' * (maxwidth + 2))
        else:
            gap = maxwidth - len(tab[i])
            indent = -1
            if gap % 2 == 0:
                indent = gap // 2
            else:
                indent = gap//2 + addleft
                addleft ^= 1
            rightindent = gap - indent
            print('*' + indent * ' ' + tab[i] + rightindent * ' ' + '*')

if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()


import sys

def solve():
    tab = list()
    maxwidth = 0
    addleft = 0
    for line in sys.stdin:
        tab.append(line.rstrip('\n'))
    for line in tab: maxwidth = max(maxwidth, len(line))
    print(maxwidth)
    for i in range(-1, len(tab) + 1):
        if i == -1 or i == len(tab):
            print('*' * (maxwidth + 2))
        else:
            gap = maxwidth - len(tab[i])
            indent = -1
            if gap % 2 == 0:
                indent = gap // 2
            else:
                indent = gap//2 + addleft
                addleft ^= 1
            rightindent = gap - indent
            print('*' + indent * ' ' + tab[i] + rightindent * ' ' + '*')

if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()


import sys
a = [l.strip() for l in sys.stdin]
w,c = max(len(l) for l in a), 0
print('*' * (w+2))
for l in a:
    s = [(w-len(l))//2] * 2
    if len(l) % 2 != w % 2:
        c = 1-c
        s[c] += 1
    print('*'+' '*s[0] + l + ' '*s[1] +'*')
print('*' * (w+2))


from sys import stdin
from math import floor

lines = []
max_len = 0
to_left = True

for line in stdin:
    lines.append(line[:-1])
    length = len(line) - 1
    if length > max_len:
        max_len = length

print('*' * (max_len + 2))
for line in lines:
    delta = max_len - len(line)
    left = right = int(floor(delta/2))
    if delta % 2 != 0:
        if to_left:
            right += 1
        else:
            left += 1
        to_left = not to_left

    out = '*' + ' ' * left + line + ' ' * right + '*'
    print(out)
print('*' * (max_len + 2))


from sys import stdin
from math import floor

lines = []
max_len = 0

for line in stdin:
    lines.append(line[:-1])
    length = len(line) - 1
    if length > max_len:
        max_len = length

print('*' * (max_len + 2))
for line in lines:
    delta = max_len - len(line)
    left = right = int(floor(delta/2))
    if delta % 2 != 0:
        right += 1
    out = '*' + ' ' * left + line + ' ' * right + '*'
    print(out)
print('*' * (max_len + 2))


"""
line = input()
while emptyCount < 1:
    maxwidth = max(maxwidth, len(line))
    lines.append(line)
    line = input()
    if line == '':
        emptyCount += 1
    else:
        emptyCount = 0
lines.pop()
"""
from sys import stdin

maxwidth = 0
lines = []

for line in stdin:
    maxwidth = max(len(line)-1, maxwidth)
    lines.append(line.strip())

# print(lines)
# print(f"max width is {maxwidth}")

newlines = []
isLeft = True

for line in lines:
    spaces = maxwidth - len(line)
    if spaces % 2 != 0:
        if isLeft:
            leftspace = spaces // 2
            rightspace = -(spaces//-2)
            isLeft = False
        else:
            leftspace = -(spaces//-2)
            rightspace = spaces // 2
            isLeft = True
        newline = "*" + " "*leftspace + line + " "*rightspace + "*"
        newlines.append(newline)
    else:
        newline = "*"+ (" "*(spaces//2)) + line + (" "*(spaces//2)) + "*"
        newlines.append(newline)

print("*"*(maxwidth+2))
for line in newlines:
    print(line)
print("*"*(maxwidth+2))


"""
line = input()
while emptyCount < 1:
    maxwidth = max(maxwidth, len(line))
    lines.append(line)
    line = input()
    if line == '':
        emptyCount += 1
    else:
        emptyCount = 0
lines.pop()
"""
from sys import stdin

maxwidth = 0
lines = []

for line in stdin:
    maxwidth = max(len(line), maxwidth)
    lines.append(line.strip())

# print(lines)
# print(f"max width is {maxwidth}")

newlines = []
isLeft = True

for line in lines:
    spaces = maxwidth - len(line)
    if spaces % 2 != 0:
        if isLeft:
            leftspace = spaces // 2
            rightspace = -(spaces//-2)
            isLeft = False
        else:
            leftspace = -(spaces//-2)
            rightspace = spaces // 2
            isLeft = True
        newline = "*" + " "*leftspace + line + " "*rightspace + "*"
        newlines.append(newline)
    else:
        newline = "*"+ (" "*(spaces//2)) + line + (" "*(spaces//2)) + "*"
        newlines.append(newline)

print("*"*(maxwidth+2))
for line in newlines:
    print(line)
print("*"*(maxwidth+2))


line = input()
maxwidth = 0
lines =[]
emptyCount = 0

while emptyCount < 2:
    maxwidth = max(maxwidth, len(line))
    lines.append(line)
    line = input()
    if line == '':
        emptyCount += 1
    else:
        emptyCount = 0
lines.pop()

print(lines)
print(f"max width is {maxwidth}")

newlines = []
isLeft = True

for line in lines:
    spaces = maxwidth - len(line)
    if spaces % 2 != 0:
        if isLeft:
            leftspace = spaces // 2
            rightspace = -(spaces//-2)
            isLeft = False
        else:
            leftspace = -(spaces//-2)
            rightspace = spaces // 2
            isLeft = True
        newline = "*" + " "*leftspace + line + " "*rightspace + "*"
        newlines.append(newline)
    else:
        newline = "*"+ (" "*(spaces//2)) + line + (" "*(spaces//2)) + "*"
        newlines.append(newline)

print("*"*(maxwidth+2))
for line in newlines:
    print(line)
print("*"*(maxwidth+2))


if __name__ == '__main__':
    buffer = []
    maxm = 0
    while 1:
        try:
            s = input().strip()
            maxm = max(maxm, len(s))
        except EOFError:
            break
    print('*' * (maxm + 2))
    for item in buffer:
        print('*' + item.center(maxm) + '*')
    print('*' * (maxm + 2))


if __name__ == '__main__':
    buffer = []
    maxm = 0
    while 1:
        try:
            s = input().strip()
            maxm = max(maxm, len(s))
            buffer.append(s)
        except EOFError:
            break
    print('*' * (maxm + 2))
    for item in buffer:
        print('*' + item.center(maxm) + '*')
    print('*' * (maxm + 2))


if __name__ == '__main__':
    buffer = []
    maxm = 0
    while 1:
        try:
            s = input().strip()
            maxm = max(maxm, len(s))
            buffer.append(s)
        except EOFError:
            break
    print('*' * (maxm + 2))
    flag = 1
    for item in buffer:
        if (maxm - len(item)) % 2 == 0:
            print('*' + item.center(maxm) + '*')
        else:
            each = (maxm - len(item)) // 2
            if flag:
                print('*' + each * ' ' + item + ' ' * (each + 1) + '*')
            else:
                print('*' + (each + 1) * ' ' + item + ' ' * each + '*')
            flag = 1 - flag
    print('*' * (maxm + 2))


import sys

def main():
    lines = sys.stdin.readlines()
    lines = [line.strip() for line in lines]
    maxlen = max(len(line) for line in lines)
    print('*' * (maxlen + 2))
    left = True
    for line in lines:
        space = maxlen - len(line)
        if space % 2 == 0:
            lpad = rpad = space // 2
        elif left:
            lpad = space // 2
            rpad = space - lpad
            left = False
        else:
            rpad = space // 2
            lpad = space - rpad
            left = True
        print('*%s%s%s*' % (' ' * lpad, line, ' ' * rpad))
    print('*' * (maxlen + 2))

main()


import sys
strs=[]

l=0
for line in sys.stdin.readlines():
	if not line:
		break
	line=line.strip()
	strs.append(line)
	l=max(l,len(line))

flag=1
print('*'*(l+2))
for i in range(len(strs)):
	print('*',end='')
	if(l-len(strs[i]))%2==0:
		x=y=(l-len(strs[i]))//2
	else:
		if flag==1:
			x=(l-len(strs[i]))//2
			y=x+1
			flag=1-flag
		else:
			x=(l-len(strs[i]))//2+1
			y=x-1
			flag=1-flag
	print(' '*x,end='')
	print(strs[i],end='')
	print(' '*y,end='')
	print('*')
print('*'*(l+2))


"""
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.

You are to implement the alignment in the shortest possible time. Good luck!

Input
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.

Output
Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
"""

import math
import sys

inputList = [k.strip() for k in sys.stdin]
maxLength = max(len(a) for a in inputList)

print((maxLength + 2) * '*')

leftSided  = True
firstSpace = 0
secondSpace = 0

for x in inputList:
    space = maxLength - len(x)
    if (space % 2): # space is odd
        firstSpace = math.ceil(space / 2) if leftSided else math.floor(space / 2)
        leftSided = not leftSided
    else:
        firstSpace = space / 2

    secondSpace = space - firstSpace

    print('*', ' ' * int(firstSpace), x, ' ' * int(secondSpace), '*', sep='')

print((maxLength + 2) * '*')


"""
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.

You are to implement the alignment in the shortest possible time. Good luck!

Input
The input file consists of one or more lines, each of the lines contains Latin letters, digits and/or spaces. The lines cannot start or end with a space. It is guaranteed that at least one of the lines has positive length. The length of each line and the total amount of the lines do not exceed 1000.

Output
Format the given text, aligning it center. Frame the whole text with characters «*» of the minimum size. If a line cannot be aligned perfectly (for example, the line has even length, while the width of the block is uneven), you should place such lines rounding down the distance to the left or to the right edge and bringing them closer left or right alternatively (you should start with bringing left). Study the sample tests carefully to understand the output format better.
"""

import math
import sys

inputList = [k.strip() for k in sys.stdin]
maxLength = max(len(a) for a in inputList)

print((maxLength + 2) * '*')

leftSided  = False
firstSpace = 0
secondSpace = 0

for x in inputList:
    space = maxLength - len(x)
    if (space % 2): # space is odd
        firstSpace = math.ceil(space / 2) if leftSided else math.floor(space / 2)
        leftSided = not leftSided
    else:
        firstSpace = space / 2

    secondSpace = space - firstSpace

    print('*', ' ' * int(firstSpace), x, ' ' * int(secondSpace), '*', sep='')

print((maxLength + 2) * '*')


from sys import stdin

def main():
  inputText =[]
  lengths = []
  for line in stdin:
    inputText.append(line[0:len(line)-1])
    lengths.append(len(line)-1)

  #get the maximum Length
  maxLength = max(lengths)

  #print the first line of *
  for i in range(maxLength+2):
    print('*',end="")
  print()

  # position text with one space to left or to right
  left = True
  for i in range(len(lengths)):
    #if both are even or both are not even, then we can center text exactely
    if (lengths[i]%2 == 0 and maxLength%2 == 0) or (lengths[i]%2 != 0 and maxLength%2 != 0):
      spaces = (maxLength - lengths[i])//2
      print('*',' '*spaces,inputText[i],' '*spaces,'*',sep='')
    else:
      if left:
        spaces = (maxLength - lengths[i] - 1)//2
        left = False
        print('*',' '*spaces,inputText[i],' '*(spaces+1),'*',sep='')
      else:
        spaces = (maxLength - lengths[i] + 1)//2
        left = True
        print('*',' '*spaces,inputText[i],' '*(spaces-1),'*',sep='')
  #print the last line of *
  for i in range(maxLength+2):
    print('*',end="")
main()


"""
Codeforces
5B - Center Alignment
http://codeforces.com/contest/5/problem/B

Héctor González Belver
../07/2018
"""
import sys

def main():
  lines = [line.strip() for line in sys.stdin.readlines()]

  max_length = max(len(line) for line in lines)

  sys.stdout.write('*' * (max_length + 2) + '\n')
  for line in lines:
    sys.stdout.write('*' + '{0:^{1}}'.format(line, max_length) + '*' + '\n')
  sys.stdout.write('*' * (max_length + 2) + '\n')

if __name__ == '__main__':
  main()


"""
Codeforces
5B - Center Alignment
http://codeforces.com/contest/5/problem/B

Héctor González Belver
../07/2018
"""
import sys

def main():
  lines = [line.strip() for line in sys.stdin.readlines()]

  max_length = max(len(line) for line in lines)

  add_space = False

  sys.stdout.write('*' * (max_length + 2) + '\n')
  for line in lines:
    if len(line)%2 != max_length%2:
      if add_space:
        line = ' ' + line
      add_space = not add_space

    sys.stdout.write('*' + '{0:^{1}}'.format(line, max_length) + '*' + '\n')
  sys.stdout.write('*' * (max_length + 2) + '\n')

if __name__ == '__main__':
  main()


"""
Codeforces
5B - Center Alignment
http://codeforces.com/contest/5/problem/B

Héctor González Belver
../07/2018
"""
import sys

def main():
  lines = []
  while True:
    line = sys.stdin.readline()
    if not line:
      break
    lines.append[line]

  max_length = max(len(line) for line in lines)

  for line in lines:
    sys.stdout.write('*' + '{0:^{1}}'.format(line, max_length) + '*' + '\n')

if __name__ == '__main__':
  main()


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        lli len=s.length(),r,size,l,ans=0,n;
        for(r=0;r<len;r++)
        {
            n=0;
            for(size=1;r-size+1>=0;size++)
            {

                if(s[r-size+1]=='1')
                {
                    n+=1<<(size-1);
                }
                if(n==size){
                    //cout<<r<<" "<<size<<" ";
                    ans++;}
            }
        }
        cout<<ans<<"\n";
    }
}
//00000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    int t;        string s;

    cin>>t;
    while(t--)
    {
        cin>>s;
        unsigned lli len=s.length(),r,size,l,ans=0,n;
        for(r=0;r<len;r++)
        {
            n=0;
            for(size=1;;size++)
            {
                if(size>r+1)break;
                //cout<<size<<" ";
                if(s[r-size+1]=='1')
                {
                    if(size>19)break;
                    n+=1<<(size-1);
                }
                if(n==size){
                    //cout<<r<<" "<<size<<" ";
                    ans++;}
            }
        }
        cout<<ans<<"\n";s.clear();
    }
}
//00000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    li t,i,j,l,ans,size;
    cin>>t;
    string s;
    while(t--)
    {
        s.clear();ans=0;size=1;
        cin>>s;l=s.length();

        for(i=0;i<l;i++)
        {
            for(size=1;size<=l-i && size<20;size++)
            {
                bitset<25> b(s,i,size);
                if(b.to_ullong()==size)
                {
                    ++ans;
                    //cout<<i<<" "<<size<<" "<<b.to_string()<<endl;
                }
            }
        }
        cout<<ans<<"\n";

    }

}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define ii int64_t
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    int t;
    string s;

    cin>>t;
    while(t--)
    {
        cin>>s;
        int64_t len=s.length(),r,ans=0,n,l;
        ii size;
        ii a[len];n=-1;
        for(r=0;r<len;r++)
        {
            if(s[r]=='1')n=r;
            a[r]=n;
            //cout<<a[r]<<" ";
        }
        for(r=0;r<len;++r)
        {
            n=0;
            for(l = r; l > 0 && r - l < 20; --l)
            {
                if(s[l] == '0') continue;
                n += 1 << (r - l);
                if(n <= r - (l==0?-1:a[l-1]))
                    ++ans;
            }
            if(l==0)
            {
                if(s[0]=='1'){
                    n+=1<<r;
                    if(n<=r+1){ans++;}}

            }

        }
        cout<<ans<<"\n";s.clear();
    }
}

//for(int r = 0; r < s.size(); ++r){
//    int sum = 0;
//    for(int l = r; l >= 0 && r - l < 20; --l){
//        if(s[l] == '0') continue;
//        sum += 1 << (r - l);
//        if(sum <= r - (l == 0? -1 : nxt[l - 1]))
//            ++res;
//    }
//}


#include <bits/stdc++.h>

using namespace std;

const int N = int(3e5) + 99;

int t;
string s;
int nxt[N];

int main() {
	cin >> t;
	for(int tc = 0; tc < t; ++tc){
		cin >> s;
		for(int i = 0; i < s.size(); ++i)
			if(s[i] == '1') nxt[i] = i;
			else nxt[i] = (i == 0? -1 : nxt[i - 1]);
		int res = 0;
		for(int r = 0; r < s.size(); ++r){
			int sum = 0;
			for(int l = r; l >= 0 && r - l < 20; --l){
				if(s[l] == '0') continue;
				sum += 1 << (r - l);
				if(sum <= r - (l == 0? -1 : nxt[l - 1]))
					++res;
			}
		}
		cout << res << endl;
	}

	return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        unsigned lli len=s.length(),r,size,l,ans=0,n;
        for(r=0;r<len;r++)
        {
            n=0;
            for(size=1;r-size+1>=0 && size<64;size++)
            {

                if(s[r-size+1]=='1')
                {
                    n+=1LL<<(size-1);
                }
                if(n==size){
                    //cout<<r<<" "<<size<<" ";
                    ans++;}
            }
        }
        cout<<ans<<"\n";
    }
}
//00000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    li t,i,j,l,ans,size;
    cin>>t;
    string s;
    while(t--)
    {
        s.clear();ans=0;size=1;
        cin>>s;l=s.length();

        for(i=0;i<l;i++)
        {
            for(size=1;size<=l-i && size<20;size++)
            {
                bitset<200005> b(s,i,size);
                if(b.to_ullong()==size)
                {
                    ++ans;
                    //cout<<i<<" "<<size<<" "<<b.to_string()<<endl;
                }
            }
        }
        cout<<ans<<"\n";

    }

}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define ii int64_t
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    int t;
    string s;

    cin>>t;
    while(t--)
    {
        cin>>s;
        int64_t len=s.length(),r,ans=0,n,l;
        ii size;
        ii a[len];n=-1;
        for(r=0;r<len;r++)
        {
            if(s[r]=='1')n=r;
            a[r]=n;
            //cout<<a[r]<<" ";
        }
        for(r=0;r<len;++r)
        {
            for(ii l = r; l >= 0 && r - l < 20; --l){
                if(s[l] == '0') continue;
                n += 1 << (r - l);
                if(n == r - l+1)
                    ++ans;
            }

        }
        cout<<ans<<"\n";s.clear();
    }
}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        lli len=s.length(),r,size,l,ans=0,n;
        for(r=0;r<len;r++)
        {
            n=0;
            for(size=1;r-size+1>=0;size++)
            {

                if(s[r-size+1]=='1')
                {
                    n+=1<<(size-1);
                }
                if(n==size){
                    cout<<r<<" "<<size<<" ";
                    ans++;}
            }
        }
        cout<<ans<<"\n";
    }
}
//00000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    int t;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        lli len=s.length(),r,size,l,ans=0,n;
        for(r=0;r<len;r++)
        {
            n=0;
            for(size=1;r-size+1>=0;size++)
            {

                if(s[r-size+1]=='1')
                {
                    n+=1LL<<(size-1);
                }
                if(n==size){
                    //cout<<r<<" "<<size<<" ";
                    ans++;}
            }
        }
        cout<<ans<<"\n";
    }
}
//00000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    int t;
    string s;

    cin>>t;
    while(t--)
    {
        cin>>s;
        unsigned lli len=s.length(),r,ans=0,n;
        int size;
        for(r=0;r<len;++r)
        {
            n=0;
            for(size=1;;++size)
            {
                if(size>r+1)break;
                //cout<<size<<" ";
                if(s[r-size+1]=='1')
                {
                    if(size>19)break;
                    n+=1<<(size-1);
                }
                if(n==size){
                    //cout<<r<<" "<<size<<" ";
                    ++ans;}
            }
        }
        cout<<ans<<"\n";s.clear();
    }
}
//00000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    li t,i,j,l,ans,size;
    cin>>t;
    string s;
    while(t--)
    {
        s.clear();ans=0;size=1;
        cin>>s;l=s.length();

        for(i=0;i<l;i++)
        {
            for(size=1;size<=l-i;size++)
            {
                bitset<10> b(s,i,size);
                if(b.to_ulong()==size)
                {
                    ++ans;
                    //cout<<i<<" "<<size<<" "<<b.to_string()<<endl;
                }
            }
        }
        cout<<ans<<"\n";

    }

}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define ii int64_t
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    int t;
    string s;

    cin>>t;
    while(t--)
    {
        cin>>s;
        int64_t len=s.length(),r,ans=0,n,l;
        ii size;
        ii a[len];n=-1;
        for(r=0;r<len;r++)
        {
            if(s[r]=='1')n=r;
            a[r]=n;
            //cout<<a[r]<<" ";
        }
        for(r=0;r<len;++r)
        {
            if(a[r]<0)continue;
            n=0;
            for(l=a[r];l>=0;)
            {

                    if(r-l>18)break;
                    n+=1LL<<(r-l);
                if(l)
                    l=a[l-1];
                    if(n<=r-l){
                        //cout<<r<<" "<<l<<" "<<n<<" ";
                        ans++;}
            }
//            for(size=1;;++size)
//            {
//                if(size>r+1)break;
//                //cout<<size<<" ";
//                if(s[r-size+1]=='1')
//                {
//                    if(size>19)break;
//                    n+=1<<(size-1);
//                }
//                if(n==size){
//                    //cout<<r<<" "<<size<<" ";
//                    ++ans;}

        }
        cout<<ans<<"\n";s.clear();
    }
}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    li t,i,j,l,ans,size;
    cin>>t;
    string s;
    while(t--)
    {
        s.clear();ans=0;size=1;
        cin>>s;l=s.length();

        for(i=0;i<l;i++)
        {
            for(size=1;size<=l-i;size++)
            {
                bitset<200005> b(s,i,size);
                if(b.to_ulong()==size)
                {
                    ++ans;
                    //cout<<i<<" "<<size<<" "<<b.to_string()<<endl;
                }
            }
        }
        cout<<ans<<"\n";

    }

}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    li t,i,j,l,ans,size;
    cin>>t;
    string s;
    while(t--)
    {
        s.clear();ans=0;size=1;
        cin>>s;l=s.length();

        for(i=0;i<l;i++)
        {
            for(size=1;size<=l-i;size++)
            {
                bitset<200005> b(s,i,size);
                if(b.to_ullong()==size)
                {
                    ++ans;
                    //cout<<i<<" "<<size<<" "<<b.to_string()<<endl;
                }
            }
        }
        cout<<ans<<"\n";

    }

}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <math.h>
#include <bitset>
#define lli long long int
#define li long int
#define ii int64_t
#define mod 1000000007
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()

{
    fio
    int t;
    string s;

    cin>>t;
    while(t--)
    {
        cin>>s;
        int64_t len=s.length(),r,ans=0,n,l;
        ii size;
        ii a[len];n=-1;
        for(r=0;r<len;r++)
        {
            if(s[r]=='1')n=r;
            a[r]=n;
            //cout<<a[r]<<" ";
        }
        cout<<endl;
        for(r=0;r<len;++r)
        {
            if(a[r]<0)continue;
            n=0;
            for(l=a[r];l>=0;)
            {

                    if(r-l>18)break;
                    n+=1LL<<(r-l);
                    l=a[l-1];
                    if(n<=r-l){
                        //cout<<r<<" "<<l<<" "<<n<<" ";
                        ans++;}
            }
//            for(size=1;;++size)
//            {
//                if(size>r+1)break;
//                //cout<<size<<" ";
//                if(s[r-size+1]=='1')
//                {
//                    if(size>19)break;
//                    n+=1<<(size-1);
//                }
//                if(n==size){
//                    //cout<<r<<" "<<size<<" ";
//                    ++ans;}

        }
        cout<<ans<<"\n";s.clear();
    }
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;
		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (j >= digits.size()) {
				cout << "ERROR" << endl;
				return 0;
			}
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = ones.size() - 1; j >= 0; j--) {
			/*if (j >= ones.size()) {
				cout << "ERROR" << endl;
				return 0;
			}*/
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				/*if (k >= digits.size()) {
					cout << "ERROR" << endl;
					return 0;
				}*/
				curr_num *= 2;
				if (digits[k] == '1') {
					curr_num++;
				}
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;
		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = ones.size() - 1; j >= 0; j--) {
			if (j >= ones.size()) {
				cout << "ERROR" << endl;
				return 0;
			}
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				/*if (k >= digits.size()) {
					cout << "ERROR" << endl;
					return 0;
				}*/
				curr_num *= 2;
				if (digits[k] == '1') {
					curr_num++;
				}
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;
		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = ones.size() - 1; j >= 0; j--) {
			if (j >= ones.size() + 1000) {
				cout << "ERROR" << endl;
				return 0;
			}
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				curr_num *= 2;
				if (digits[k] == '1') {
					curr_num++;
				}
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;
		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (j >= digits.size()) {
				cout << "ERROR" << endl;
				return 0;
			}
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = ones.size() - 1; j >= 0; j--) {
			if (j >= ones.size()) {
				cout << "ERROR" << endl;
				return 0;
			}
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				if (k >= digits.size()) {
					cout << "ERROR" << endl;
					return 0;
				}
				curr_num *= 2;
				if (digits[k] == '1') {
					curr_num++;
				}
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;
		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = ones.size() - 1; j >= 0; j--) {
			if (j == ones.size() + 1) {
				cout << "ERROR" << endl;
				return 0;
			}
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				curr_num *= 2;
				if (digits[k] == '1') {
					curr_num++;
				}
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;
		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = ones.size() - 1; j >= 0; j--) {
			if (j == ones.size()) {
				cout << "ERROR" << endl;
				return 0;
			}
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				curr_num *= 2;
				if (digits[k] == '1') {
					curr_num++;
				}
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;

		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = ones.size() - 1; j >= 0; j--) {
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				curr_num *= 2;
				curr_num += digits[k] - '0';
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;
		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = ones.size() - 1; j >= 0; j--) {
			if (j >= ones.size() + 10) {
				cout << "ERROR" << endl;
				return 0;
			}
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				curr_num *= 2;
				if (digits[k] == '1') {
					curr_num++;
				}
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;
		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = ones.size() - 1; j >= 0; j--) {
			if (j == ones.size() + 2) {
				cout << "ERROR" << endl;
				return 0;
			}
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				curr_num *= 2;
				if (digits[k] == '1') {
					curr_num++;
				}
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;

		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = ones.size() - 1; j >= 0; j--) {
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				curr_num *= 2;
				if (digits[k] == '1') {
					curr_num++;
				}
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define ll long long int
#define ld long double
#define vec vector
#define forn(a) for(ll a=0; a<n; a++)
#define fore(a, v, n) for(ll a=v; a<n; a++)
#define all(x) x.begin(), x.end()
#define presicion(x) cout<<fixed<<setprecision(x)
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define PI 3.14159265358979323
#define sen(ang) sin((ang)*PI/180)
//cout<<flush;

using namespace std;

int main() {
	IOS;

	ll t;
	cin >> t;

	fore (i, 0, t) {
		string digits;
		cin >> digits;
		ll count = 0;
		vector<ll> ones;
		for (ll j = 0; j < digits.size(); j++) {
			if (digits[j] == '1') {
				ones.push_back(j);
				count++;
			}
		}

		for (ll j = 0; j < ones.size(); j++) {
			ll curr_i = ones[j];
			ll curr_num = 1;
			ll zeroes = curr_i;
			if (j != 0) {
				zeroes = curr_i - ones[j - 1] - 1;
			}
			for (ll k = curr_i + 1; k < digits.size(); k++) {
				curr_num *= 2;
				if (digits[k] == '1') {
					curr_num++;
				}
				ll num_dig = k - curr_i + 1 + zeroes;
				if (num_dig >= curr_num) {
					count++;
				} else {
					break;
				}
			}
		}

		cout << count << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string bindec(int a){
string s="";int b=a;
for(int j=0;j<b;j++)
    {s+=((char)(a%2)+'0');
    a=a>>1;}
    reverse(s.begin(),s.end());//cout<<s<<endl;
return s;}
int main(){
int t;
cin>>t;
while(t--){
    string s;int cn=0,x=0;cin>>s;
    vector<string>vc;
    for(int i=1;i<=s.size();i++){
        vc.push_back(bindec(i));//cout<<i<<endl;
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            for(int j=i;j<s.size();j++){
                x=x*2+((int)s[j]-'0');//cout<<"x "<<x<<endl;
                if(j+1-x>=0 && vc[x-1].compare(s.substr(j+1-x,x))==0 )
                    {cn++;}//cout<<s.substr(j+1-x,x)<<endl;}
            }
        }
        x=0;
    }
    cout<<cn<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
string bindec(int a){
string s="";int b=a;
for(int j=0;j<b;j++)
    {s+=((char)(a%2)+'0');
    a=a>>1;}
    reverse(s.begin(),s.end());//cout<<s<<endl;
return s;}
int main(){
int t;
cin>>t;
while(t--){
    string s;int cn=0;cin>>s;
    vector<string>vc;
    for(int i=1;i<=s.size();i++){
        vc.push_back(bindec(i));//cout<<i<<endl;
    }
    for(int i=1;i<=s.size();i++){
        for(int j=i;j<=s.size();j++){
            if(vc[j-i].compare(s.substr(i-1,j-i+1))==0)
                {cn++;}
        }
    }
    cout<<cn<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
string bindec(int a){
string s="";int b=a;
for(int j=0;j<b;j++)
    {s+=((char)(a%2)+'0');
    a=a>>1;}
    reverse(s.begin(),s.end());//cout<<s<<endl;
return s;}
int main(){
int t;
cin>>t;
while(t--){
    string s;int cn=0;long long x=0;cin>>s;
    //vector<string>vc;
   // for(int i=1;i<=s.size();i++){
      //  vc.push_back(bindec(i));//cout<<i<<endl;
    //}
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            for(int j=i;j<s.size();j++){
                x=x*2+((int)s[j]-'0');//cout<<"x "<<x<<endl;
                string st=bindec(x-1);
                if(j+1-x>=0 && st.compare(s.substr(j+1-x,x))==0 )
                    {cn++;}
                else
                    break;//cout<<s.substr(j+1-x,x)<<endl;}
            }
        }
        x=0;
    }
    cout<<cn<<endl;vc.clear();
}
}


#include<bits/stdc++.h>
using namespace std;
string bindec(int a){
string s="";int b=a;
for(int j=0;j<b;j++)
    {s+=((char)(a%2)+'0');
    a=a>>1;}
    reverse(s.begin(),s.end());//cout<<s<<endl;
return s;}
int main(){
int t;
cin>>t;
while(t--){
    string s;int cn=0;long long x=0;cin>>s;
    vector<string>vc;
    for(int i=1;i<=s.size();i++){
        vc.push_back(bindec(i));//cout<<i<<endl;
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            for(int j=i;j<s.size();j++){
                x=x*2+((int)s[j]-'0');//cout<<"x "<<x<<endl;
                if(j+1-x>=0 && vc[x-1].compare(s.substr(j+1-x,x))==0 )
                    {cn++;}
                else
                    break;//cout<<s.substr(j+1-x,x)<<endl;}
            }
        }
        x=0;
    }
    cout<<cn<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
string bindec(int a){
string s="";int b=a;
for(int j=0;j<b;j++)
    {s+=((char)(a%2)+'0');
    a=a>>1;}
    reverse(s.begin(),s.end());//cout<<s<<endl;
return s;}
int main(){
int t;
cin>>t;
while(t--){
    string s;int cn=0;cin>>s;
    vector<string>vc;
    for(int i=1;i<=s.size();i++){
        vc.push_back(bindec(i));//cout<<i<<endl;
    }
    for(int i=1;i<=s.size();i++){
        if(s[i-1]=='1'){
        for(int j=i;j<=s.size();j++){
            if(vc[j-i].compare(s.substr(i-1,j-i+1))==0)
                {cn++;}
        }
    }
    }
    cout<<cn<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
string bindec(int a){
string s="";int b=a;
for(int j=0;j<b;j++)
    {s+=((char)(a%2)+'0');
    a=a>>1;}
    reverse(s.begin(),s.end());//cout<<s<<endl;
return s;}
int main(){
int t;
cin>>t;
while(t--){
    string s;int cn=0;long long x=0;cin>>s;
    vector<string>vc;
    for(int i=1;i<=s.size();i++){
        vc.push_back(bindec(i));//cout<<i<<endl;
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            for(int j=i;j<s.size();j++){
                x=x*2+((int)s[j]-'0');//cout<<"x "<<x<<endl;
                if(j+1-x>=0 && vc[x-1].compare(s.substr(j+1-x,x))==0 )
                    {cn++;}//cout<<s.substr(j+1-x,x)<<endl;}
            }
        }
        x=0;
    }
    cout<<cn<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
string bindec(int a){
string s="";int b=a;
for(int j=0;j<b;j++)
    {s+=((char)(a%2)+'0');
    a=a>>1;}
    reverse(s.begin(),s.end());//cout<<s<<endl;
return s;}
int main(){
int t;
cin>>t;
while(t--){
    string s;int cn=0;long long x=0;cin>>s;
    //vector<string>vc;
   // for(int i=1;i<=s.size();i++){
      //  vc.push_back(bindec(i));//cout<<i<<endl;
    //}
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            for(int j=i;j<s.size();j++){
                x=x*2+((int)s[j]-'0');//cout<<"x "<<x<<endl;
                string st=bindec(x);
                if(j+1-x>=0 && st.compare(s.substr(j+1-x,x))==0 )
                    {cn++;}
                else
                    break;//cout<<s.substr(j+1-x,x)<<endl;}
            }
        }
        x=0;
    }
    cout<<cn<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int binary(string s)
{
	int i=0;
	int num=0;
//	cout<<s<<endl;
	for(int j=s.length()-1;j>=0;j--)
	{
		if(s[j] == '1')
			num = num + pow(2,i)*1;
		i++;
	}
	return num;
}
signed main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string str;
		cin>>str;
		int n = str.length();
		int l, p;
		int ans = 0;
		int x=1;
		for(int i=0;i<n;i++)
		{
			p =0;
			int z=2;
			int g = log2(x);
			g++;
			int f=g;
			g = x-g;
//			cout<<f<<" ";
			if(g>=200000)
				break;
			for(int j=0;j<=n-x;j++)
			{
				int k=1;
				l=j;
				for(l=j;l<j+g;l++)
				{
					if(str[l] == 1)
					{
						k=0;
						break;
					}
				}
				if(k==0)
				{
//					j=l+1;
				}
				else
				{
					int num = binary(str.substr(j, x));
//					cout<<num<<" ";
					if(num == x)
					{
						ans++;
					}
				}
			}
//			cout<<ans<<" "<<x<<endl;
			x++;
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int binary(string s)
{
	int i=0;
	int num=0;
//	cout<<s<<endl;
	for(int j=s.length()-1;j>=0;j--)
	{
		if(s[j] == '1')
			num = num + pow(2,i)*1;
		i++;
	}
	return num;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		string str;
		cin>>str;
		int n = str.length();
		int l, p;
		int ans = 0;
		int x=1;
		for(int i=0;i<n;i++)
		{
			p =0;
			int z=2;
			int g = log2(x);
			g++;
			int f=g;
			g = x-g;
//			cout<<f<<" ";
			if(g>=200000)
				break;
			for(int j=0;j<=n-x;j++)
			{
				int k=1;
				l=j;
				for(l=j;l<j+g;l++)
				{
					if(str[l] == 1)
					{
						k=0;
						break;
					}
				}
				if(k==0)
				{
//					j=l+1;
				}
				else
				{
//					int num = binary(str.substr(j, x));
					int value = stoi(str.substr(j, x), 0, 2);
//					cout<<num<<" ";
					if(value == x)
					{
						ans++;
					}
//					j=j+x;
				}
			}
//			cout<<ans<<" "<<x<<endl;
			x++;
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int binary(string s)
{
	int i=0;
	int num=0;
//	cout<<s<<endl;
	for(int j=s.length()-1;j>=0;j--)
	{
		if(s[j] == '1')
			num = num + pow(2,i)*1;
		i++;
	}
	return num;
}
signed main()
{
	int t;
	cin>>t;
	while(t--)
	{
		string str;
		cin>>str;
		int n = str.length();
		int l, p;
		int ans = 0;
		int x=1;
		for(int i=0;i<n;i++)
		{
			p =0;
			int z=2;
			int g = log2(x);
			g++;
			int f=g;
			g = x-g;
//			cout<<f<<" ";
			if(g>=200000)
				break;
			for(int j=0;j<=n-x;j++)
			{
				int k=1;
				l=j;
				for(l=j;l<j+g;l++)
				{
					if(str[l] == 1)
					{
						k=0;
						break;
					}
				}
				if(k==0)
				{
//					j=l+1;
				}
				else
				{
					int num = binary(str.substr(j, x));
//					cout<<num<<" ";
					if(num == x)
					{
						ans++;
					}
				}
			}
			cout<<ans<<" "<<x<<endl;
			x++;
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int binary(string s)
{
	int i=1;
	int num=0;
//	cout<<s<<endl;
	for(int j=s.length()-1;j>=0;j--)
	{
		if(s[j] == '1')
			num = num + i;
		i = i*2;
	}
	return num;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		string str;
		cin>>str;
		int n = str.length();
		int l, p;
		int ans = 0;
		int x=1;
		for(int i=0;i<n;i++)
		{
			p =0;
			int z=2;
			int g = log2(x);
			g++;
			int f=g;
			g = x-g;
//			cout<<f<<" ";
			if(g>=200000)
				break;
			for(int j=0;j<=n-x;j++)
			{
				int k=1;
				l=j;
				for(l=j;l<j+g;l++)
				{
					if(str[l] == '1')
					{
						k=0;
						break;
					}
				}
				if(k==0)
				{
//					j=l+1;
				}
				else
				{
					int num = binary(str.substr(j, x));
//					cout<<num<<" ";
					if(num == x)
					{
						ans++;
					}
//					j=j+x;
				}
			}
//			cout<<ans<<" "<<x<<endl;
			x++;
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int binary(string s)
{
	int i=0;
	int num=0;
//	cout<<s<<endl;
	for(int j=s.length()-1;j>=0;j--)
	{
		if(s[j] == '1')
			num = num + pow(2,i)*1;
		i++;
	}
	return num;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		string str;
		cin>>str;
		int n = str.length();
		int l, p;
		int ans = 0;
		int x=1;
		for(int i=0;i<n;i++)
		{
			p =0;
			int z=2;
			int g = log2(x);
			g++;
			int f=g;
			g = x-g;
//			cout<<f<<" ";
			if(g>=200000)
				break;
			for(int j=0;j<=n-x;j++)
			{
				int k=1;
				l=j;
				for(l=j;l<j+g;l++)
				{
					if(str[l] == 1)
					{
						k=0;
						break;
					}
				}
				if(k==0)
				{
//					j=l+1;
				}
				else
				{
					int num = binary(str.substr(j, x));
//					cout<<num<<" ";
					if(num == x)
					{
						ans++;
					}
//					j=j+x;
				}
			}
//			cout<<ans<<" "<<x<<endl;
			x++;
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int binary(string s)
{
	int i=1;
	int num=0;
//	cout<<s<<endl;
	for(int j=s.length()-1;j>=0;j--)
	{
		if(s[j] == '1')
			num = num + i;
		i = i*2;
	}
	return num;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		string str;
		cin>>str;
		int n = str.length();
		int arr[n] = {0};
		int ans=0;
		arr[0] = 0;
		for(int i=1;i<n;i++)
		{
			if(str[i-1] == '0')
			{
				arr[i] = arr[i-1]+1;
			}
			else
			{
				arr[i] = 0;
			}
		}
		for(int i=0;i<n;i++)
		{
			if(str[i] == '0')
			{
				continue;
			}
			else
			{
				for(int j=i;j<n;j++)
				{
					int val = binary(str.substr(i, j-i+1));
					int x = val - (j-i+1);
//					cout<<val<<" "<<x<<endl;
					if(arr[i]>=x)
						ans++;
					else
						break;
				}
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int binary(string n)
{
	string num = n;
    int dec_value = 0;

    // Initializing base value to 1, i.e 2^0
    int base = 1;

    int len = num.length();
    for (int i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		string str;
		cin>>str;
		int n = str.length();
		int l, p;
		int ans = 0;
		int x=1;
		for(int i=0;i<n;i++)
		{
			p =0;
			int z=2;
			int g = log2(x);
			g++;
			int f=g;
			g = x-g;
//			cout<<f<<" ";
			if(g>=200000)
				break;
			for(int j=0;j<=n-x;j++)
			{
				int k=1;
				l=j;
				for(l=j;l<j+g;l++)
				{
					if(str[l] == 1)
					{
						k=0;
						break;
					}
				}
				if(k==0)
				{
//					j=l+1;
				}
				else
				{
					int num = binary(str.substr(j, x));
//					int value = stoi(str.substr(j, x), 0, 2);
//					cout<<num<<" ";
					if(num == x)
					{
						ans++;
					}
//					j=j+x;
				}
			}
//			cout<<ans<<" "<<x<<endl;
			x++;
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>

using namespace std;

int fun(string s)
{
    int n = 0,m = s.size()-1;
    for(int i = 0;i < s.size();i++){
        if(s[m] == '1')
            n += pow(2,i);
        m--;
    }
    return n;
}

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        for(int i = 0;i < s.size();i++){
                 string s1 = "";
              if(s[i] == '1')cnt++;
               s1 += s[i];
            for(int j = i+1;j < s.size();j++){
                s1 += s[j];
                int n = fun(s1);
                if(j-i+1 == n)cnt++;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        //cout << s[39] << endl;
        for(int i = s.size()-1;i >= 0;i--){
             long long int n = 0;
              if(s[i] == '1'){
                    cnt++;
                   n += 1;
              }
            int f = 0;
            for(int j = i-1;j >= 0;j--){
                  //  if(i == 75 && j == 39)cout << "problem : " << n << endl;
                    f++;
            if(s[j] == '1'){
                   n += pow(2,f);
                    if(n > 200001)break;
            }
               if(i-j+1 == n){
                    cnt++;
            //   cout << i << " " << j << " " << n <<endl;
               }
        //    if(i == 75)cout << "problem : " << n << endl;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int fun(string s)
{
    int n = 0,m = s.size()-1;
    for(int i = 0;i < s.size();i++){
        if(s[m] == '1')
            n += 1<<i;
        m--;
    }
    return n;
}

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        for(int i = 0;i < s.size();i++){
                 string s1 = "";
              if(s[i] == '1')cnt++;
               s1 += s[i];
            for(int j = i+1;j < s.size();j++){
                s1 += s[j];
                int n = fun(s1);
                if(j-i+1 == n)cnt++;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        for(int i = s.size()-1;i >= 0;i--){
                 int n = 0,x=1;
              if(s[i] == '1'){
                    cnt++;
                    n += 1;
              }
            for(int j = i-1;j >= 0;j--){
               if(s[j] == '1')n += pow(2,x);
               if(i-j+1 == n)cnt++;
               x++;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int fun(string s)
{
    int n = 0,m = s.size()-1;
    for(int i = 0;i < s.size();i++){
        if(s[m] == '1')
            n += (1<<i);
        m--;
    }
    return n;
}

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        for(int i = 0;i < s.size();i++){
                 string s1 = "";
              if(s[i] == '1')cnt++;
               s1 += s[i];
            for(int j = i+1;j < s.size();j++){
                s1 += s[j];
                int n = fun(s1);
                if(j-i+1 == n)cnt++;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        for(int i = s.size()-1;i >= 0;i--){
               long long n = 0,base = 1;
              if(s[i] == '1'){
                    cnt++;
                    n += base;
              }
            base *= 2;
            for(int j = i-1;j >= 0;j--){
            if(s[j] == '1'){
                    n += base;
            }
            base *= 2;
               if(i-j+1 == n)cnt++;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        for(int i = s.size()-1;i >= 0;i--){
                 int n = 0,base = 1;
              if(s[i] == '1'){
                    cnt++;
                    n += base;
              }
            base *= 2;
            for(int j = i-1;j >= 0;j--){
            if(s[j] == '1'){
                    n += base;
            }
            base *= 2;
               if(i-j+1 == n)cnt++;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        //cout << s[39] << endl;
        for(int i = s.size()-1;i >= 0;i--){
             long long int n = 0;
              if(s[i] == '1'){
                    cnt++;
                   n += 1;
              }
            int f = 0;
            for(int j = i-1;j >= 0;j--){
                  //  if(i == 75 && j == 39)cout << "problem : " << n << endl;
                    f++;
            if(s[j] == '1'){
                    if(f > 18)break;
                   n += 1<<f;
            }
               if(i-j+1 == n){
                    cnt++;
            //   cout << i << " " << j << " " << n <<endl;
               }
        //    if(i == 75)cout << "problem : " << n << endl;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        for(int i = s.size()-1;i >= 0;i--){
             long long int n = 0;
              if(s[i] == '1'){
                    cnt++;
                   n += 1;
              }
            int f = 0;
            for(int j = i-1;j >= 0;j--){
                    f++;
            if(s[j] == '1'){
                   n += 1<<f;
            }
               if(i-j+1 == n){
                    cnt++;
               }
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        //cout << s[39] << endl;
        for(int i = s.size()-1;i >= 0;i--){
              int n = 0;
              if(s[i] == '1'){
                    cnt++;
                   n += 1;
              }
            int f = 0;
            for(int j = i-1;j >= 0;j--){
            if(n > 200001)break;
                    f++;
            if(s[j] == '1'){
                    if(f > 18)break;
                   n += 1<<f;
            }
               if(i-j+1 == n){
                    cnt++;
               }
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0,m;
        cin >> s;
        for(int i = 0;i < s.size();i++)
        if(s[i] == '1'){
            m = i;
            break;
        }
        for(int i = s.size()-1;i >= m;i--){
              int n = 0;
              if(s[i] == '1'){
                    cnt++;
                   n += 1;
              }
            int f = 0;
            for(int j = i-1;j >= 0;j--){
            if(n > 200001)break;
                    f++;
            if(s[j] == '1'){
                    if(f > 18)break;
                   n += 1<<f;
            }
               if(i-j+1 == n){
                    cnt++;
               }
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        for(int i = s.size()-1;i >= 0;i--){
                 int n = 0,x=1;
              if(s[i] == '1'){
                    cnt++;
                    n += 1;
              }
            for(int j = i-1;j >= 0;j--){
               if(s[j] == '1')n += (1<<x);
               if(i-j+1 == n)cnt++;
               x++;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        for(int i = s.size()-1;i >= 0;i--){
               unsigned long long int n = 0,base = 1;
              if(s[i] == '1'){
                    cnt++;
                    n += base;
              }
            base *= 2;
            for(int j = i-1;j >= 0;j--){
            if(s[j] == '1'){
                    n += base;
            }
               if(i-j+1 == n)cnt++;
                base *= 2;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    string s;
    cin >> t;
    while(t--){
        int cnt = 0;
        cin >> s;
        //cout << s[39] << endl;
        for(int i = s.size()-1;i >= 0;i--){
             long long int n = 0;
              if(s[i] == '1'){
                    cnt++;
                   n += 1;
              }
            int f = 0;
            for(int j = i-1;j >= 0;j--){
                  //  if(i == 75 && j == 39)cout << "problem : " << n << endl;
                    f++;
            if(s[j] == '1'){
                    if(f > 22)break;
                   n += 1<<f;
            }
               if(i-j+1 == n){
                    cnt++;
            //   cout << i << " " << j << " " << n <<endl;
               }
        //    if(i == 75)cout << "problem : " << n << endl;
            }
        }
            cout << cnt << endl;
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include <functional>
#include<map>
#include <queue>
#include<deque>
#include<set>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(8)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define rsz resize
#define sz(c) ((int)c.size())
#define MAXP 5000
typedef long long ll;
char sl='\n';
vector<int>bb[MAXP];
vector<string>tx;
vector<int> Pr(string s) {
    vector<int> p(s.size());
    for (int i = 1; i < (int)s.size(); ++i) {
        int j = p[i - 1];
        while (j > 0 && s[i] != s[j])
            j = p[j - 1];
        if (s[i] == s[j])
            j++;
        p[i] = j;
    }
    return p;
}

void go()
{
	for(int i=1;i<MAXP;++i)
	{
		int a=log2(i)+1;
		string bit="";
		for(int j=0;j<a;++j)
		{
			if(int(i>>j)&1)bit.p_b('1');
			else
			bit.p_b('0');
		}
		for(int j=a;j<i;++j)
		bit.p_b('0');
		string y(bit.rbegin(),bit.rend());
		tx.p_b(y);
		bb[i-1]=Pr(y);
	}
}
int bp(vector<int>p,string t,string s){
	int cnt = 0;

    	int j = 0;
    for (int i = 0; i < (int)t.size(); ++i) {
        while (j > 0 && t[i] != s[j])
            j = p[j - 1];
        if (t[i] == s[j])
            j++;
        if (j == (int)s.size())
            cnt++;
    }
	return cnt;
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int t;
	//cin>>t;
	//cout<<1<<endl;
	go();
	//cout<<2<<endl;
	cin>>t;
	while(t--)
	{

		string x;
		cin>>x;
		int ans(0);
		for(int i=0;i<tx.size();++i)ans+=bp(bb[i],x,tx[i]);

		cout<<ans<<sl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include <functional>
#include<map>
#include <queue>
#include<deque>
#include<set>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(8)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define rsz resize
#define sz(c) ((int)c.size())
#define MAXP 1010101010
typedef long long ll;
char sl='\n';
vector<int>bb[1000];
vector<string>tx;
vector<int> Pr(string s) {
    vector<int> p(s.size());
    for (int i = 1; i < (int)s.size(); ++i) {
        int j = p[i - 1];
        while (j > 0 && s[i] != s[j])
            j = p[j - 1];
        if (s[i] == s[j])
            j++;
        p[i] = j;
    }
    return p;
}

void go()
{
	for(int i=1;i<1000;++i)
	{
		int a=log2(i)+1;
		string bit="";
		for(int j=0;j<a;++j)
		{
			if(int(i>>j)&1)bit.p_b('1');
			else
			bit.p_b('0');
		}
		for(int j=a;j<i;++j)
		bit.p_b('0');
		string y(bit.rbegin(),bit.rend());
		tx.p_b(y);
		bb[i-1]=Pr(y);
	}
}
int bp(vector<int>p,string t,string s){
	int cnt = 0;

    	int j = 0;
    for (int i = 0; i < (int)t.size(); ++i) {
        while (j > 0 && t[i] != s[j])
            j = p[j - 1];
        if (t[i] == s[j])
            j++;
        if (j == (int)s.size())
            cnt++;
    }
	return cnt;
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int t;
	//cin>>t;
	//cout<<1<<endl;
	go();
	//cout<<2<<endl;
	cin>>t;
	while(t--)
	{

		string x;
		cin>>x;
		int ans(0);
		for(int i=0;i<tx.size();++i)ans+=bp(bb[i],x,tx[i]);

		cout<<ans<<sl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include <functional>
#include<map>
#include <queue>
#include<deque>
#include<set>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(8)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define rsz resize
#define sz(c) ((int)c.size())
#define MAXP 3000
typedef long long ll;
char sl='\n';
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int t;
	cin>>t;
	while(t--)
	{
		string x;
		cin>>x;
		int zeros(0);
		int ans(0);
		for(int i=0;i<x.size();++i)
		{
			if(x[i]=='0')zeros++;
			else{
				int r=1;
				int number(0);
				for(int j=i;j<(i+18)&&j<x.size();++j)
				{
					number<<=1;
					if(x[j]=='1')
					number|=1;
					if(number==r||(r+zeros)>=number)ans++;
					r++;

				}
				zeros=0;
			}
		}
		cout<<ans<<sl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include <functional>
#include<map>
#include <queue>
#include<deque>
#include<set>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(8)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define rsz resize
#define sz(c) ((int)c.size())
#define MAXP 3000
typedef long long ll;
char sl='\n';
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int t;
	cin>>t;
	while(t--)
	{
		string x;
		cin>>x;
		int zeros(0);
		int ans(0);
		int b=log2(x.size())+1;
		for(int i=0;i<x.size();++i)
		{
			if(x[i]=='0')zeros++;
			else{
				int r=1;
				int number(0);
				for(int j=i;j<(i+18)&&j<x.size();++j)
				{
					number<<=1;
					if(x[j]=='1')
					number|=1;
					if(number==r||(r+zeros)>=number)ans++;
				//	cout<<"n: "<<number<<" i: "<<i<<" j: "<<j<<" ans: "<<ans<<sl;
					r++;

				}
				zeros=0;
			}
		}
		cout<<ans<<sl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include <functional>
#include<map>
#include <queue>
#include<deque>
#include<set>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(8)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define rsz resize
#define sz(c) ((int)c.size())
#define MAXP 1010101010
typedef long long ll;
char sl='\n';
vector<int>bb[1000];
vector<string>tx;
vector<int> kmppre(string &P) //by gabina with love
 {
 vector<int>b;
 b.clear();
 b.rsz(P.size());
 int i =0, j=-1; b[0]=-1;
 while(i<sz(P))
 {
 while(j>=0 && P[i] != P[j]) j=b[j];
 i++, j++;
 b[i] = j;
 }
 return b;
}

void go()
{
	for(int i=1;i<1000;++i)
	{
		int a=log2(i)+1;
		string bit="";
		for(int j=0;j<a;++j)
		{
			if(int(i>>j)&1)bit.p_b('1');
			else
			bit.p_b('0');
		}
		for(int j=a;j<i;++j)
		bit.p_b('0');
		string y(bit.rbegin(),bit.rend());
		tx.p_b(y);
		bb[i-1]=kmppre(y);
	}
}
 //back table b[i] maximo borde de [0..i)
int kmp(string &T, string &P,vector<int>&b) //Text, Pattern -- O(|T|+|P|)
 {
 //kmppre(P);
 int ans(0);
  int sizet=T.size();
 int sizeb=P.size();
 int i=0, j=0;
 while(i<sizet)
 {
 while(j>=0 && T[i]!=P[j]) j=b[j];
 i++, j++;
 if(j==sizeb)
 {
	++ans;
	 j=b[j];

	}

	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int t;
	//cin>>t;
	cout<<1<<endl;
	go();
	cout<<2<<endl;
	cin>>t;
	while(t--)
	{

		string x;
		cin>>x;
		int ans(0);
		for(int i=0;i<tx.size();++i)ans+=kmp(x,tx[i],bb[i]);

		cout<<ans<<sl;
	}

	return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include <functional>
#include<map>
#include <queue>
#include<deque>
#include<set>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(8)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define rsz resize
#define sz(c) ((int)c.size())
#define MAXP 1010101010
typedef long long ll;
char sl='\n';
vector<string>bb;
class trie
{
public:
	map<char,trie> h;
	bool e;
	int k;
	trie():e(false),k(0){};
	void insert(const string &x)
	{
		trie *p=this;
		for(char c:x) {
			p=&p->h[c];
			p->e=true;
		//	p->k++;
			p->k++;

		}
	}

	int _find(const string &x) {
		trie *p=this;
		int ans(0);
		bool existe=1;
		for(char c:x)
		{
			if(p->h.find(c)!=p->h.end())
			p=&p->h[c];
			else
			return 0;
		}

		if(p->e)
		{
			ans=p->k;
			return ans;
		}
		return 0;
	}
};
void go()
{
	for(int i=1;i<1000;++i)
	{
		int a=log2(i)+1;
		string bit="";
		for(int j=0;j<a;++j)
		{
			if(int(i>>j)&1)bit.p_b('1');
			else
			bit.p_b('0');
		}
		for(int j=a;j<i;++j)
		bit.p_b('0');
		bb.p_b(string(bit.rbegin(),bit.rend()));
	}
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int t;
	//cin>>t;
	go();
	cin>>t;
	while(t--)
	{
		trie god;
		string x;
		cin>>x;
		for(int j=0;j<x.size();++j)
		god.insert(x.substr(j,x.size()-j));
		int ans(0);
		for(string i:bb)ans+=god._find(i);
		cout<<ans<<sl;

	}

	return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include <functional>
#include<map>
#include <queue>
#include<deque>
#include<set>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(8)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define rsz resize
#define sz(c) ((int)c.size())
#define MAXP 3000
typedef long long ll;
char sl='\n';
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int t;
	cin>>t;
	while(t--)
	{
		string x;
		cin>>x;
		int zeros(0);
		int ans(0);
		int b=log2(x.size())+1;
		for(int i=0;i<x.size();++i)
		{
			if(x[i]=='0')zeros++;
			else{
				int r=1;
				int number(0);
				for(int j=i;j<(i+17)&&j<x.size();++j)
				{
					number<<=1;
					if(x[j]=='1')
					number|=1;
					if(number==r||(r+zeros)>=number)ans++;
				//	cout<<"n: "<<number<<" i: "<<i<<" j: "<<j<<" ans: "<<ans<<sl;
					r++;

				}
				zeros=0;
			}
		}
		cout<<ans<<sl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include <functional>
#include<map>
#include <queue>
#include<deque>
#include<set>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(8)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define rsz resize
#define sz(c) ((int)c.size())
#define MAXP 3000
typedef long long ll;
char sl='\n';
vector<int>bb[MAXP];
vector<string>tx;
vector<int> Pr(string s) {
    vector<int> p(s.size());
    for (int i = 1; i < (int)s.size(); ++i) {
        int j = p[i - 1];
        while (j > 0 && s[i] != s[j])
            j = p[j - 1];
        if (s[i] == s[j])
            j++;
        p[i] = j;
    }
    return p;
}

void go()
{
	for(int i=1;i<MAXP;++i)
	{
		int a=log2(i)+1;
		string bit="";
		for(int j=0;j<a;++j)
		{
			if(int(i>>j)&1)bit.p_b('1');
			else
			bit.p_b('0');
		}
		for(int j=a;j<i;++j)
		bit.p_b('0');
		string y(bit.rbegin(),bit.rend());
		tx.p_b(y);
		bb[i-1]=Pr(y);
	}
}
int bp(vector<int>p,string t,string s){
	int cnt = 0;

    	int j = 0;
    for (int i = 0; i < (int)t.size(); ++i) {
        while (j > 0 && t[i] != s[j])
            j = p[j - 1];
        if (t[i] == s[j])
            j++;
        if (j == (int)s.size())
            cnt++;
    }
	return cnt;
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int t;
	//cin>>t;
	//cout<<1<<endl;
	go();
	//cout<<2<<endl;
	cin>>t;
	while(t--)
	{

		string x;
		cin>>x;
		int ans(0);
		for(int i=0;i<tx.size();++i)ans+=bp(bb[i],x,tx[i]);

		cout<<ans<<sl;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include <functional>
#include<map>
#include <queue>
#include<deque>
#include<set>
using namespace std;
#define fi first
#define se second
#define p_b push_back
#define mk_p make_pair
#define pr_setp(n)cout<<setprecision(2)<<n;
#define pr_setp1(n)cout<<setprecision(8)<<fixed<<n;
#define l_b lower_bound
#define u_b upper_bound
#define rsz resize
#define sz(c) ((int)c.size())
#define MAXP 2000
typedef long long ll;
char sl='\n';
vector<int>bb[MAXP];
vector<string>tx;
vector<int> Pr(string s) {
    vector<int> p(s.size());
    for (int i = 1; i < (int)s.size(); ++i) {
        int j = p[i - 1];
        while (j > 0 && s[i] != s[j])
            j = p[j - 1];
        if (s[i] == s[j])
            j++;
        p[i] = j;
    }
    return p;
}

void go()
{
	for(int i=1;i<MAXP;++i)
	{
		int a=log2(i)+1;
		string bit="";
		for(int j=0;j<a;++j)
		{
			if(int(i>>j)&1)bit.p_b('1');
			else
			bit.p_b('0');
		}
		for(int j=a;j<i;++j)
		bit.p_b('0');
		string y(bit.rbegin(),bit.rend());
		tx.p_b(y);
		bb[i-1]=Pr(y);
	}
}
int bp(vector<int>p,string t,string s){
	int cnt = 0;

    	int j = 0;
    for (int i = 0; i < (int)t.size(); ++i) {
        while (j > 0 && t[i] != s[j])
            j = p[j - 1];
        if (t[i] == s[j])
            j++;
        if (j == (int)s.size())
            cnt++;
    }
	return cnt;
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	int t;
	//cin>>t;
	//cout<<1<<endl;
	go();
	//cout<<2<<endl;
	cin>>t;
	while(t--)
	{

		string x;
		cin>>x;
		int ans(0);
		for(int i=0;i<tx.size();++i)ans+=bp(bb[i],x,tx[i]);

		cout<<ans<<sl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
li res;
class dop
{public:
li n,p,q,r;
string s;
void get();
};
li power(li x,li n)
{res=1;
while(n>0){if(n&1){res=res*x;}
x=x*x;n=n>>1;}return res;}
void dop::get()
{cin>>s;n=s.length();r=0;
for(li i=n-1;i>=0;i--){p=(0);if(s[i]=='1'){p=1;r++;}if(i>=18){q=i-18;}else{q=0;}
for(li j=i-1;j>=q;j--){if(s[j]=='1'){p+=power(2,i-j);}
if(p==(i-j+1)){r++;}}}
cout<<r<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
li res;
class dop
{public:
li n,p,q,r,e;
string s;
void get();
};
li power(li x,li n)
{res=1;
while(n>0){if(n&1){res=res*x;}
x=x*x;n=n>>1;}return res;}
void dop::get()
{cin>>s;n=s.length();r=0;e=2e5;
for(li i=n-1;i>=0;i--){p=0;
for(li j=i;j>=0;j--){if(s[j]=='1'){if((i-j)<=20){p+=power(2,i-j);}else{break;}}
if(p==(i-j+1)){r++;if((i-j)>=20){break;}}if(p>e){break;}}}
cout<<r<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
li res;
class dop
{public:
string s,a;
li p,q,r,v;
bool y;
void get();
};
li power(li x,li n)
{res=1;
while(n>0){if(n&1){res=res*x;}
x=x*x;n=n>>1;}
return res;}
void dop::get()
{cin>>s;p=0;r=0;
for(li i=s.length()-1;i>=0;i--){p=0;y=true;v=i;
for(li j=i;j>=0;j--){if(s[j]=='1'){
if((i-j+1)<=64){q=int(s[j])-48;p+=(q*(power(2,(i-j+1))/2));if(p==(i-j+1)){r++;}}
    else{break;}}
}
}cout<<r<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
li t;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
li res;
class dop
{public:
li n,p,q,r,e;
string s;
void get();
};
li power(li x,li n)
{res=1;
while(n>0){if(n&1){res=res*x;}
x=x*x;n=n>>1;}return res;}
void dop::get()
{cin>>s;n=s.length();r=0;e=2e5;
for(li i=n-1;i>=0;i--){p=0;
for(li j=i;j>=0;j--){if(s[j]=='1'){if((i-j)<=20){p+=power(2,i-j);}else{break;}}
if(p==(i-j+1)){r++;}if(p<=(i-j+1)){if((i-j)>=20){break;}}}}
cout<<r<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
li res;
class dop
{public:
li n,p,q,r,e;
string s;
void get();
};
li power(li x,li n)
{res=1;
while(n>0){if(n&1){res=res*x;}
x=x*x;n=n>>1;}return res;}
void dop::get()
{cin>>s;n=s.length();r=0;e=2e5;
for(li i=n-1;i>=0;i--){p=0;
for(li j=i;j>=0;j--){if(s[j]=='1'){p+=power(2,i-j);}
if(p==(i-j+1)){r++;}if(p>e){break;}}}
cout<<r<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
li res;
class dop
{public:
string s,a;
li p,q,r,v;
bool y;
void get();
};
li power(li x,li n)
{res=1;
while(n>0){if(n&1){res=res*x;}
x=x*x;n=n>>1;}
return res;}
void dop::get()
{cin>>s;p=0;r=0;
for(li i=s.length()-1;i>=0;i--){p=0;y=true;v=i;
for(li j=i;j>=0;j--){if(s[j]=='1'){
if((i-j+1)<=64){q=int(s[j])-48;p+=(q*(power(2,(i-j+1))/2));if(p==(i-j+1)){r++;}}
    else{break;}}
    else{if(p==(i-j+1)){r++;}}
}
}cout<<r<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
li t;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
li res;
class dop
{public:
li n,p,q,r,e;
string s;
void get();
};
li power(li x,li n)
{res=1;
while(n>0){if(n&1){res=res*x;}
x=x*x;n=n>>1;}return res;}
void dop::get()
{cin>>s;n=s.length();r=0;e=2e5;
for(li i=n-1;i>=0;i--){p=(0);if(s[i]=='1'){p=1;r++;}if(i>=18){q=i-18;}else{q=0;}
for(li j=i-1;j>=0;j--){if(s[j]=='1'){p+=power(2,i-j);}
if(p==(i-j+1)){r++;}if(p>e){break;}}}
cout<<r<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
#define le long double
li res;
class dop
{public:
li n,p,q,r,e;
string s;
void get();
};
li power(li x,li n)
{res=1;
while(n>0){if(n&1){res=res*x;}
x=x*x;n=n>>1;}return res;}
void dop::get()
{cin>>s;n=s.length();r=0;e=2e5;
for(li i=n-1;i>=0;i--){p=0;
for(li j=i;j>=0;j--){if(s[j]=='1'){if((i-j)<=20){p+=power(2,i-j);}else{break;}}
if(p==(i-j+1)){r++;}if(p>e){break;}}}
cout<<r<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
li t;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
li res;
class dop
{public:
string s,a;
li p,q,r,v;
bool y;
void get();
};
li power(li x,li n)
{res=1;
while(n>0){if(n&1){res=res*x;}
x=x*x;n=n>>1;}
return res;}
void dop::get()
{cin>>s;p=0;r=0;
for(li i=s.length()-1;i>=0;i--){p=0;y=true;v=i;
for(li j=i;j>=0;j--){q=int(s[j])-48;p+=(q*(power(2,(i-j+1))/2));
//cout<<i<<" "<<j<<" "<<p<<'\n';
if(p==(i-j+1)){r++;}}
}cout<<r<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
li t;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define li long long int
li res;
class dop
{public:
string s,a;
li p,q,r,v;
bool y;
void get();
};
li power(li x,li n)
{res=1;
while(n>0){if(n&1){res=res*x;}
x=x*x;n=n>>1;}
return res;}
void dop::get()
{cin>>s;p=0;r=0;
for(li i=s.length()-1;i>=0;i--){p=0;y=true;v=i;
for(li j=i;j>=0;j--){if((i-j+1)<=64){q=int(s[j])-48;p+=(q*(power(2,(i-j+1))/2));
//
if(p==(i-j+1)){r++;}}}
}cout<<r<<'\n';
}
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
li t;
cin>>t;
dop obj[t];
for(li i=0;i<t;i++){obj[i].get();}
return 0;}


include<bits/stdc++.h>
using namespace std;

define ll long long

int main()
{
	ll t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;

		ll len = s.length();
		ll count = 0;
		ll prevZero = 0;
		for(ll l=0;l<len;l++)
		{
			if(s[l]=='0')
			{
				prevZero++;
				continue;
			}

			ll num = 1;
			count++;
			for(ll r=l+1;r<len;r++)
			{
				num *= 2;
				num += (s[r] == '0') ? 0LL : 1LL;

				int right = (r-l+1);

				if(right+prevZero>=num && num>=right)
				{
					count++;
					continue;
				}
				else
				{
					prevZero = 0;
					break;
				}
			}
		}

		cout << count << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
	ll t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;

		ll len = s.length();
		ll count = 0;

		for(ll l=0;l<len;l++)
		{
			ll num = (s[l] == '0') ? 0LL : 1LL;
			if(s[l]=='1') count++;
			for(ll r=l+1;r<len;r++)
			{
				num *= 2;
				num += (s[r] == '0') ? 0LL : 1LL;

				//cout << l << " " << r << " " << num << endl;
				//num += 	(s[r] == '0') ? 0LL : pow(2,r-l);
				if(num==(r-l+1))
				{
					count++;
				}
			}
		}

		cout << count << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
	ll t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;

		ll len = s.length();
		ll count = 0;
		ll prevZero = 0;
		for(ll l=0;l<len;l++)
		{
			if(s[l]=='0')
			{
				prevZero++;
				continue;
			}

			ll num = 1;
			count++;
			for(ll r=l+1;r<len;r++)
			{
				num *= 2;
				num += (s[r] == '0') ? 0LL : 1LL;

				int right = (r-l+1);

				if(num>len) break;

				else if(right+prevZero<num)
				{
					prevZero = 0;
					break;
				}
				else if(num>=right && num<=right+prevZero)
				{
					count++;
					continue;
				}
			}
		}

		cout << count << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
	ll t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;

		ll len = s.length();
		ll count = 0;
		ll prevZero = 0;
		for(ll l=0;l<len;l++)
		{
			if(s[l]=='0')
			{
				prevZero++;
				continue;
			}

			ll num = 1;
			count++;
			for(ll r=l+1;r<len;r++)
			{
				num *= 2;
				num += (s[r] == '0') ? 0LL : 1LL;

				int right = (r-l+1);

				if(num==right)
				{
					count++;
					continue;
				}

				int needed = num-right;
				if(needed<=prevZero)
				{
					count++;
					continue;
				}
				else
				{
					prevZero = 0;
					break;
				}
				//if(num==(r-l+1))
				//{
				//	count++;
				//}
			}
		}

		cout << count << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
	ll t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;

		ll len = s.length();
		ll count = 0;
		ll prevZero = 0;
		for(ll l=0;l<len;l++)
		{
			if(s[l]=='0')
			{
				prevZero++;
				continue;
			}

			ll num = 1;
			count++;
			for(ll r=l+1;r<len;r++)
			{
				num *= 2;
				num += (s[r] == '0') ? 0LL : 1LL;

				int right = (r-l+1);

				if(right+prevZero>=num)
				{
					count++;
					continue;
				}
				else
				{
					prevZero = 0;
					break;
				}
			}
		}

		cout << count << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
	ll t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;

		ll len = s.length();
		ll count = 0;
		ll prevZero = 0;
		for(ll l=0;l<len;l++)
		{
			if(s[l]=='0')
			{
				prevZero++;
				continue;
			}

			ll num = 1;
			count++;
			for(ll r=l+1;r<len;r++)
			{
				num *= 2;
				num += (s[r] == '0') ? 0LL : 1LL;

				int right = (r-l+1);

				if(right+prevZero>=num)
				{
					count++;
					continue;
				}
				else
				{
					prevZero = 0;
					break;
				}
				//if(num==(r-l+1))
				//{
				//	count++;
				//}
			}
		}

		cout << count << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
	ll t;
	cin >> t;

	while(t--)
	{
		string s;
		cin >> s;

		ll len = s.length();
		ll count = 0;
		ll prevZero = 0;
		for(ll l=0;l<len;l++)
		{
			if(s[l]=='0')
			{
				prevZero++;
				continue;
			}

			ll num = 1;
			count++;
			for(ll r=l+1;r<len;r++)
			{
				num *= 2;
				num += (s[r] == '0') ? 0LL : 1LL;

				int right = (r-l+1);

				if(right+prevZero>=num && num>=right)
				{
					count++;
					continue;
				}
				else
				{
					prevZero = 0;
					break;
				}
			}
		}

		cout << count << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
	ll t;
	cin >> t;

	while(t--)
	{
		string s;
        cin>>s;
        int cnt=0;
        int ans=0;
        for(int i=0;i<s.length();++i){
            if(s[i]=='0'){
                ++cnt;
            }else{
                int len=0;
                for(int j=i;j<min((int)s.length(),i+20);++j){
                    len=len*2+s[j]-'0';
                    if(len>=j-i+1&&len<=j-i+1+cnt){
                        ++ans;
                    }
                }
                cnt=0;
            }
        }
        cout<<ans<<endl;
	}
}


//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define Ahmed_El_Moataz           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fo(i,a,b)                 for(int i=(a);i<(b);i++)
#define ll long long
#define ld long double
#define endl "\n"
#define ull unsigned long long
#define ALL(v) ((v).begin()), ((v).end())
#define INCREASING(v) sort(ALL(v))
#define DECREASING(v) INCREASING(v), reverse(ALL(v))
#define ReadFile freopen("input.in","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f,NegOO= -1*OO;
double Pi=acos(-1);
const double long rad=Pi/180.0;
ll GCD(ll a,ll b){return (b == 0) ? a : GCD (b, a % b);}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}
ll Pow(ll b, ll p){return (p)?((p & 1)? b:0) + Pow((b<<1),(p>>1)):1;}
ll nCr (ll n,ll m){return(m == 0)?1:n*nCr(n-1,m-1)/m;}
/*****************************************************/

int main()
{
    Ahmed_El_Moataz
    int T;cin>>T;
    while(T--){
        string s;cin>>s;
        ll Fans=0,t=s.size();
        fo(i,0,t){
            ll co=0,_size=0;
            fo(j,i,t){
                co=co<<1;_size++;
                if(s[j]=='1'){
                    co++;
                }
                if(_size==co)Fans++;
            }
        }
        cout<<Fans<<endl;
    }

}
/*
*/


//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define Ahmed_El_Moataz           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fo(i,a,b)                 for(int i=(a);i<(b);i++)
#define ll long long
#define ld long double
#define endl "\n"
#define ull unsigned long long
#define ALL(v) ((v).begin()), ((v).end())
#define INCREASING(v) sort(ALL(v))
#define DECREASING(v) INCREASING(v), reverse(ALL(v))
#define ReadFile freopen("input.in","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f,NegOO= -1*OO;
double Pi=acos(-1);
const double long rad=Pi/180.0;
ll GCD(ll a,ll b){return (b == 0) ? a : GCD (b, a % b);}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}
ll Pow(ll b, ll p){return (p)?((p & 1)? b:0) + Pow((b<<1),(p>>1)):1;}
ll nCr (ll n,ll m){return(m == 0)?1:n*nCr(n-1,m-1)/m;}
/*****************************************************/

int main()
{
    Ahmed_El_Moataz
    int T;cin>>T;
    while(T--){
        string s;cin>>s;
        ll Fans=0,t=s.size();
        for(int i=t-1;i>=0;i--){
            ll co=0,_size=0,temp=1;
            for(int j=i;j>=0;j--){
                _size++;
                if(s[j]=='1'){
                    co+=temp;
                }
                if(_size==co)Fans++;
                temp = temp<<1;
                if(co>t || temp > 500000)break;
            }
        }
        cout<<Fans<<"\n";
    }

}
/*
*/


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define Ahmed_El_Moataz           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fo(i,a,b)                 for(int i=(a);i<(b);i++)
#define ll long long
#define ld long double
#define endl "\n"
#define ull unsigned long long
#define ALL(v) ((v).begin()), ((v).end())
#define INCREASING(v) sort(ALL(v))
#define DECREASING(v) INCREASING(v), reverse(ALL(v))
#define ReadFile freopen("input.in","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f,NegOO= -1*OO;
double Pi=acos(-1);
const double long rad=Pi/180.0;
ll GCD(ll a,ll b){return (b == 0) ? a : GCD (b, a % b);}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}
ll Pow(ll b, ll p){return (p)?((p & 1)? b:0) + Pow((b<<1),(p>>1)):1;}
ll nCr (ll n,ll m){return(m == 0)?1:n*nCr(n-1,m-1)/m;}
/*****************************************************/

int main()
{
    Ahmed_El_Moataz
    int T;cin>>T;
    while(T--){
        string s;cin>>s;
        ll Fans=0,t=s.size();
        for(int i=t-1;i>=0;i--){
            ll co=0,_size=0,temp=1;
            for(int j=i;j>=0;j--){
                _size++;
                if(s[j]=='1'){
                    co+=temp;
                }
                if(_size==co)Fans++;
                temp = temp*2;
                if(temp > 500000)break;
            }
        }
        cout<<Fans<<"\n";
    }

}
/*
*/