#include <bits/stdc++.h>
using namespace std;
int FindVal(string str, int end, int st) {
  int val = 0;
  int p = 1;
  while (end >= st) {
    val = val + p * (str[end] - '0');
    p *= 2;
    end--;
  }
  return val;
}
int main() {
  int k = 20;
  int n;
  cin >> n;
  int prev;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    int l = (int)str.size();
    prev = 0;
    long long ans = 0;
    for (int j = 0; j < l; j++) {
      if (str[j] == '0') {
        prev++;
        continue;
      }
      for (int p = j; p < l && p < (j + k); p++) {
        int val = FindVal(str, p, j);
        if ((val - (p - j + 1)) <= prev)
          ans++;
        else
          break;
      }
      prev = 0;
    }
    cout << ans << '\n';
  }
  return 0;
}
