#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    vector<int> v;
    int n = s.length();
    for (int i = 0; s[i]; i++) {
      if (s[i] == '1') v.push_back(i);
    }
    v.push_back(n);
    int cnt = 0;
    for (int ST = 0; ST < n; ST++) {
      int sum = 0;
      int curr_pos = *lower_bound(v.begin(), v.end(), ST);
      while (curr_pos < n) {
        int p = curr_pos - ST;
        if (p >= 20) break;
        sum += (long long)ceil(pow(2, p));
        int next_pos = *upper_bound(v.begin(), v.end(), curr_pos);
        int len = next_pos - ST;
        if (len >= sum) cnt++;
        curr_pos = next_pos;
      }
    }
    cout << cnt << endl;
  }
}
