#include <bits/stdc++.h>
const long long N = 1e6 + 10;
const long long INF = 1e18;
const long long inf = -1e18;
const long long MOD1 = 1e9 + 1;
const long long MOD = 1e9 + 1;
using namespace std;
long long res, sum, cnt, nxt[N];
string s;
long long binpow(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2 == 0) return binpow(a, n / 2) * binpow(a, n / 2);
  if (n % 2 != 0) return binpow(a, n - 1) * a;
}
void solve() {
  cin >> s;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == '1')
      nxt[i] = i;
    else {
      if (i == 0) {
        nxt[i] = -1;
      } else {
        nxt[i] = nxt[i - 1];
      }
    }
  res = 0;
  for (int r = 0; r < s.size(); ++r) {
    sum = 0;
    for (int l = r; l >= 0 && r - l < 20; --l) {
      if (s[l] == '0') continue;
      sum += 1 << (r - l);
      if (sum <= r - (l == 0 ? -1 : nxt[l - 1])) ++res;
    }
  }
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  long long o = 1;
  cin >> o;
  while (o--) {
    solve();
  }
}
