#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
map<int, multiset<int>> mp;
int T;
string s;
int main() {
  fast();
  cin >> T;
  while (T--) {
    cin >> s;
    int n = s.size();
    int z[n + 1];
    fill(z, z + n + 1, 0);
    if (s[0] == '0') z[0] = 1;
    for (int i = 1; i < n; i++) {
      if (s[i] == '0') z[i] = z[i - 1] + 1;
    }
    int cnt = 0;
    for (int j = 0; j < n; j++) {
      int x = 1;
      int ret = 0;
      for (int i = j; i >= max(0, j - 18); i--) {
        if (s[i] == '1') {
          ret += x;
          if (ret > 200000) break;
          if (i == 0) {
            if ((j - i + 1) >= ret) cnt++;
          } else if (z[i - 1] + (j - i + 1) >= ret)
            cnt++;
        }
        x <<= 1;
      }
    }
    cout << cnt << '\n';
  }
  return 0;
}
