#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string itos(int n) {
  stringstream ss;
  ss << n;
  string second = ss.str();
  return second;
}
long long ppow(long long x, long long y, long long mod) {
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x % mod;
    y >>= 1;
    x = x * x % mod;
  }
  return res;
}
int main() {
  cout << fixed << setprecision(10);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string second;
    cin >> second;
    vector<int> a(second.size());
    vector<int> p(second.size());
    p[0] = second[0] - '0' - 1;
    int cnt = 0;
    for (int i = 1; i < second.size(); ++i) {
      if (second[i] == '1') {
        p[i] = i;
      } else {
        p[i] = p[i - 1];
      }
    }
    for (int r = 0; r < second.size(); ++r) {
      int sum = 0;
      for (int l = r; l > -1 && r - l <= 20; --l) {
        if (second[l] == '0') {
          continue;
        }
        sum += 1 << (r - l);
        if (sum <= r - (l == 0 ? -1 : p[l - 1])) {
          cnt++;
        }
      }
    }
    cout << cnt << '\n';
  }
}
