#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int n = (int)s.size();
    int zero[n], cnt = int(s[0] == '0'), ans = 0;
    zero[0] = cnt;
    for (int i = 1; i < n; i++) {
      if (s[i] == '0')
        cnt++;
      else
        cnt = 0;
      zero[i] = cnt;
    }
    for (int r = 0; r < n; r++) {
      int num = 0;
      for (int l = r; l >= 0 && r - l <= 18; l--) {
        if (s[l] == '1') {
          num += (1 << (r - l));
          if ((r - l + 1) + (l == 0 ? 0 : zero[l - 1]) >= num) ans++;
        }
      }
    }
    cout << ans << '\n';
  }
  return (0);
}
