#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<int> uns;
    uns.push_back(-1);
    for (int i = 0; i < int(s.size()); i++) {
      if (s[i] == '1') uns.push_back(i);
    }
    long long ans = 0;
    printf("\n");
    for (long long i = 0; i < int(s.size()); i++) {
      long long sum = 0;
      long long j = lower_bound((uns).begin(), (uns).end(), i) - uns.begin();
      if (j >= int(uns.size()) || uns[j] > i) j--;
      for (bool sair = false; !sair && sum < 500010; j--) {
        long long ind = uns[j];
        if (ind == -1 || (i - ind) > 20) {
          sair = true;
        }
        if ((i - ind) >= sum && sum != 0) {
          ans++;
        }
        if (!sair) {
          sum += 1LL << (i - ind);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
