#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long maxN = 3e5 + 5, N = 2e3 + 5;
long long n, k, a[maxN], p[maxN];
void solve() {
  string second;
  cin >> second;
  n = second.length();
  long long ans = 0;
  p[0] = 0;
  for (long long i = 1; i <= n; i++) a[i] = (second[i - 1] - '0');
  for (long long i = 1; i <= n; i++) p[i] = p[i - 1] + a[i];
  for (long long i = 1; i <= n; i++) {
    if (a[i] == 1) {
      long long x = 1;
      ans++;
      for (long long j = i + 1; j < min(n + 1, i + 18); j++) {
        x = x * 2 + (a[j] == 1 ? 1 : 0);
        long long zero = x - (j - i + 1);
        if ((i - zero >= 1 && (p[i - 1] - p[i - zero - 1]) == 0) || zero == 0) {
          if (zero == 1) {
            if (a[i - 1] == 0) ans++;
          } else
            ans++;
        }
      }
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long t = 1;
  cin >> t;
  while (t--) solve();
}
