#include <bits/stdc++.h>
int t, n;
std::string s;
std::vector<std::string> v[200001];
int main() {
  std::cin >> t;
  for (int i = 1; i <= 200000; ++i) {
    int val = i;
    std::string m;
    while (val > 0) {
      m += ('0' + val % 2);
      val /= 2;
    }
    std::reverse(m.begin(), m.end());
    v[i - m.size()].push_back(std::move(m));
  }
  while (t--) {
    std::cin >> s;
    n = s.size();
    int cnt0 = 0, ans = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '0')
        cnt0++;
      else {
        while (cnt0 >= 0) {
          for (auto str : v[cnt0])
            if (i + str.size() <= n && str == s.substr(i, str.size())) ++ans;
          --cnt0;
        }
        cnt0 = 0;
      }
    }
    std::cout << ans << "\n";
  }
}
