#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> p(n);
    p.back() = n - 1;
    for (int i = n - 2; ~i; --i) p[i] = s[i] == '1' ? i : p[i + 1];
    int res = 0;
    for (int i = 0; i != n; ++i) {
      int j = p[i];
      if (s[j] == '0') continue;
      for (int l = j - i + 1, x = 0; j != n; ++j) {
        x += s[j] == '1';
        res += l == x;
        if ((x <<= 1) > (1 << 18)) break;
        ++l;
      }
    }
    cout << res << endl;
  }
}
