#include <bits/stdc++.h>
using namespace std;
int zc[200005];
int zr(int n) {
  int tmp = n;
  int len = 0;
  while (n) {
    len++;
    n /= 2;
  }
  return tmp - len;
}
int main() {
  int t;
  string s;
  cin >> t;
  while (t--) {
    cin >> s;
    int n = s.length();
    int cur = 0;
    for (int i = 0; i < n; i++) {
      zc[i] = cur;
      if (s[i] == '1')
        cur = 0;
      else
        cur++;
    }
    list<pair<int, int>> li;
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') {
        for (auto it = li.begin(); it != li.end();) {
          it->first *= 2;
          it->first += 1;
          if (zr(it->first) > it->second) {
            auto t = it;
            t++;
            li.erase(it);
            it = t;
          } else {
            ans++;
            it++;
          }
        }
        li.push_back(make_pair(1, zc[i]));
        ans++;
      } else {
        for (auto it = li.begin(); it != li.end();) {
          it->first *= 2;
          if (zr(it->first) > it->second) {
            auto t = it;
            t++;
            li.erase(it);
            it = t;
          } else {
            ans++;
            it++;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
