#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = (int)s.size();
    vector<int> nxt(n);
    int pos = -1;
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') pos = i;
      nxt[i] = pos;
    }
    int ans = 0;
    for (int r = 0; r < n; r++) {
      int val = 0;
      for (int l = r; r - l < 19 && l >= 0; l--) {
        if (s[l] == '0') continue;
        val += 1 << (r - l);
        if (val <= r - ((l != 0) ? nxt[l - 1] : -1)) ans++;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
