#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long int n = s.size();
    long long int pre[n + 1];
    memset(pre, 0, sizeof(pre));
    for (long long int i = 1; i <= n; i++) {
      if (s[i - 1] == '0') pre[i] = pre[i - 1] + 1;
    }
    long long int last[n + 1];
    memset(last, 0, sizeof(last));
    for (long long int i = 1; i <= n; i++) {
      last[i] = last[i - 1];
      if (s[i - 1] == '1') last[i] = i;
    }
    long long int ans = 0;
    for (long long int i = 1; i <= n; i++) {
      long long int x = 0;
      long long int cs = 0;
      long long int mj = max(1LL, i - 25LL);
      long long int j = i;
      while (j >= mj) {
        cs += (s[j - 1] - '0') * (1 << x);
        long long int val = i - j + 1;
        long long int len = cs - val;
        if (pre[j - 1] >= len && len >= 0) ans++;
        x += (j - last[j - 1]);
        j = last[j - 1];
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
