#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    string cad;
    cin >> cad;
    long long N = cad.size();
    cad = "*" + cad;
    long long A[N + 1];
    for (long long i = 0; i <= N; i++) {
      A[i] = 0;
    }
    for (long long i = 1; i <= N; i++) {
      if (cad[i] == '0') A[i] += A[i - 1] + 1;
    }
    long long res = 0;
    for (long long i = 1; i <= N; i++) {
      if (cad[i] == '1') {
        long long num = 0;
        for (long long j = i; j <= min(i + 20, N); j++) {
          num = num * 2 + (cad[j] - '0');
          if (j - i + 1 <= num && num <= j - i + 1 + A[i - 1]) res++;
        }
      }
    }
    cout << res << '\n';
  }
  return 0;
}
