#include <bits/stdc++.h>
using namespace std;
void tc() {
  string s;
  cin >> s;
  long cnt = 0, n = s.length() + 1;
  int a[n];
  for (int i = 0; i < n - 1; i++) a[i + 1] = s[i] - '0';
  a[0] = 1;
  int next[n];
  next[0] = 0;
  for (int i = 1; i < n; i++) next[i] = (a[i] == 1 ? i : next[i - 1]);
  for (int i = n - 1; i >= 1; i--) {
    int ans = 0, j = next[i];
    while (i - j < 18 && j) {
      int len = i - j;
      ans += 1 << len;
      if (len + j - next[j - 1] >= ans) cnt++;
      j = next[j - 1];
    }
  }
  cout << cnt << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) tc();
  ;
}
