#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
const int inf = 0x3f3f3f3f;
int T, n;
int main() {
  cin >> T;
  string s;
  for (int t = 0; t < T; t++) {
    cin >> s;
    n = s.length();
    int ans = 0, pre = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0')
        pre++;
      else {
        int r = i, cur = 1;
        for (int j = 1; j <= 18; j++) {
          if (cur <= pre + (r - i + 1)) ans++;
          if (r + 1 >= n) break;
          cur = cur * 2 + (s[++r] - '0');
        }
        pre = 0;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
