------
## 最终结论
```python
def count_good_substrings(t, queries):
    results = []
    
    for s in queries:
        n = len(s)
        good_count = 0
        
        for i in range(n):
            value = 0
            length = 0
            
            for j in range(i, min(n, i + 20)):  # Limit the length to avoid overflow
                value = value * 2 + int(s[j])
                length += 1
                
                if length == value:
                    good_count += 1
        
        results.append(good_count)
    
    return results

# Reading input
t = int(input())
queries = [input().strip() for _ in range(t)]

# Processing and outputting results
results = count_good_substrings(t, queries)
for result in results:
    print(result)
```