#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    string s;
    cin >> s;
    int n = s.size();
    if (n == 1) {
      printf("%d\n", s == "1");
      continue;
    }
    long long ans = 0;
    for (int((i)) = (0); ((i)) < ((n)); ++((i)))
      if (s[i] == '1') ++ans;
    for (int((i)) = (0); ((i)) < ((n - 1)); ++((i)))
      if (s[i] == '1' && s[i + 1] == '0') ++ans;
    int l = 0;
    while (l < n) {
      while (l < n && s[l] == '1') ++l;
      if (l == n) break;
      int m = l;
      while (m < n && s[m] == '0') ++m;
      int r = m;
      int tmp = 0;
      while (r < n) {
        tmp *= 2;
        tmp += s[r] - '0';
        if (tmp > r - l + 1) break;
        ++r;
        if (tmp != 1 && tmp != 2) ++ans;
      }
      l = m;
    }
    printf("%lld\n", ans);
  }
}
