#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long n = (long long)s.size();
    long long ans = 0;
    vector<long long> pref(n + 1, 0);
    for (long long i = 0; i < n; i++) {
      pref[i + 1] = pref[i] + (s[i] == '0');
      if (s[i] == '1') {
        long long len = 0;
        long long val = 0;
        for (long long j = i; j < min(n, i + 18); j++) {
          len++;
          val *= 2;
          if (s[j] == '1') {
            val++;
          }
          if (val == len) {
            ans++;
          } else if (val > len) {
            long long rem = val - len;
            long long cur = i - rem;
            if (cur >= 0 and s[cur] == '0') {
              long long sum = pref[i] - pref[cur];
              if (sum == rem) {
                ans++;
              }
            }
          }
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
