#include <bits/stdc++.h>
using namespace std;
int ans(string s) {
  int l;
  l = s.length();
  int numbers[l];
  numbers[0] = 0;
  for (int i = 1; i < l; i++) {
    if (s[i - 1] == '0') {
      numbers[i] = numbers[i - 1] + 1;
    } else {
      numbers[i] = 0;
    }
  }
  int counter = 0;
  for (int i = 0; i < l; i++) {
    int present = 0;
    int tempo = min(l - 1, i + 17);
    int temp = s[i] - 48;
    if (temp == 0) {
      continue;
    }
    for (int j = i; j <= tempo; j++) {
      temp = s[j] - 48;
      present = present * 2 + temp;
      if ((numbers[i] + j - i + 1) >= present) {
        counter++;
      } else {
        break;
      }
    }
  }
  return counter;
}
int main() {
  int t;
  cin >> t;
  string s;
  getline(cin, s);
  for (int k = 0; k < t; k++) {
    s.clear();
    getline(cin, s);
    cout << ans(s) << endl;
  }
  return 0;
}
