#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long n = s.size();
    vector<long long> a(n);
    long long ans = 0;
    a[0] = s[0] == '0';
    for (long long i = 1; i < n; i++) {
      if (s[i] == '0') {
        a[i] = a[i - 1] + 1;
      } else {
        a[i] = 0;
      }
    }
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') {
        long long cnt = 0;
        if (i != 0) {
          cnt = a[i - 1];
        }
        long long cur = 0;
        for (long long j = i; j < n; j++) {
          cur *= 2;
          cur += s[j] - '0';
          if (cur > n) {
            break;
          }
          long long len = j - i + 1;
          if (cur - len <= cnt) {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
