#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const int INF = 0x3f3f3f3f;
int nxt[MAX * 2];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int ans = 0;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
      nxt[i] = (s[i] == '1' ? i : (i == 0 ? -1 : nxt[i - 1]));
    for (int r = 0; r < s.size(); r++) {
      int val = 0;
      for (int l = r; l >= 0 && r - l < 20; l--) {
        if (s[l] == '1') {
          val += (1 << (r - l));
          if (val - (r - l + 1) <= (l ? (l - nxt[l - 1] - 1) : (l))) {
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
