#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int l = s.size(), cnt = 0, i, total = 0, value, j, digits;
    int dp[l];
    memset(dp, 0, sizeof(dp));
    for (i = 0; i < l; i++) {
      if (s[i] == '1') {
        dp[i] = cnt;
        cnt = 0;
      } else {
        cnt++;
      }
    }
    for (i = 0; i < l; i++) {
      if (s[i] == '1') {
        total++;
        value = 1;
        digits = 1;
        for (j = i + 1; j < l && digits <= 20; j++) {
          digits++;
          value = (value << 1);
          value = s[j] == '1' ? value + 1 : value;
          if (digits + dp[i] >= value) {
            total++;
          }
        }
      }
    }
    cout << total << endl;
  }
  return 0;
}
