#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int t, pos[200010];
string s;
int main() {
  cin >> t;
  while (t--) {
    cin >> s;
    if (s[0] == '1')
      pos[0] = 0;
    else
      pos[0] = -1;
    for (int i = 1; i < s.size(); i++) {
      if (s[i] == '1')
        pos[i] = i;
      else
        pos[i] = pos[i - 1];
    }
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
      int sum = 0;
      for (int j = i; j >= 0 && (i - j) < 20; j--) {
        if (s[j] == '0') continue;
        sum += 1 << (i - j);
        if (sum <= i - (j == 0 ? -1 : pos[j - 1])) ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
