#include <bits/stdc++.h>
using namespace std;
class Solution {
 public:
  Solution() {
    string s;
    cin >> s;
    vector<int> nxt(s.size()), sum(s.size());
    for (int i = 0; i < s.size(); i++) {
      nxt[i] = -1;
      sum[i] = (i != 0 ? sum[i - 1] : 0) + s[i] - '0';
    }
    for (int i = 0; i < s.size(); i++) {
      int j = i + 1;
      int x = s[i] - '0';
      if (x == 1) {
        x = 2 * x + s[j] - '0';
        j++;
        while (j - x >= 0 && j <= s.size()) {
          if ((i >= 1 ? sum[i - 1] : 0) -
                  (j - x - 1 >= 0 ? sum[j - x - 1] : 0) ==
              0)
            nxt[j - x] = j;
          x = 2 * x + s[j] - '0';
          j++;
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
      ans += (nxt[i] == -1 ? 0 : 1);
      if (s[i] == '1') ans++;
    }
    cout << ans << '\n';
  }
};
int main() {
  iostream::sync_with_stdio(false);
  int q;
  cin >> q;
  while (q) {
    auto x = new Solution();
    delete x;
    q--;
  }
}
