#include <bits/stdc++.h>
using namespace std;
int t, n;
string str;
int main() {
  cin >> t;
  while (t--) {
    long long res = 0;
    cin >> str;
    n = str.size();
    for (int i = 0; i < n; i++)
      if (str[i] == '1') res++;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (str[i] == '0')
        cnt++;
      else {
        int num = 1, len = 1;
        for (int j = i + 1; j < min(i + 20, n); j++) {
          num <<= 1;
          if (str[j] == '1') num++;
          len++;
          if (num <= len + cnt)
            res++;
          else
            break;
        }
        cnt = 0;
      }
    }
    cout << res << endl;
  }
  return 0;
}
