#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9, MAXN = 1e5;
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int nu = 0;
    int cur = 0;
    int l = 0, r = 0;
    int ans = 0;
    while (l < s.size()) {
      while (l < s.size() && s[l] == '0') {
        ++nu;
        ++l;
      }
      if (l == s.size()) break;
      r = l;
      int b = 0;
      cur = 0;
      while (cur < 2 * 1e5 && r < s.size()) {
        cur = (cur << 1) + (s[r] == '1');
        b++;
        r++;
        if (b + nu >= cur) ++ans;
      }
      l++;
      nu = 0;
    }
    cout << ans << endl;
  }
  return 0;
}
