#include <bits/stdc++.h>
using namespace std;
int t, zero, cur;
long long ans;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> s;
    ans = zero = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '0') {
        if (i == 0 || s[i - 1] == '1') {
          zero = 1;
        } else {
          zero++;
        }
      } else {
        cur = 0;
        if (i == 0 || s[i - 1] == '1') {
          zero = 0;
        }
        int b = min(i + 18, (int)s.size());
        for (int j = i; j < b; j++) {
          cur = cur * 2 + (s[j] - '0');
          if ((j - i + 1) + min(zero, cur - (j - i + 1)) == cur) {
            ans++;
          }
        }
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
