#include <bits/stdc++.h>
using namespace std;
int func(string s, vector<int> umap) {
  int i, j, ans = 0;
  while (1) {
    for (i = 0; i < s.length(); i++) {
      if (s[i] == '1') break;
    }
    if (i == s.length()) return ans;
    int qq = 2 + upper_bound(umap.begin(), umap.end(), i) - umap.begin();
    int f = 0;
    if (s.length() - i < qq) {
      for (j = 1; i + j < s.length(); j++) {
        if (s[i + j] == '0') break;
      }
      if (i + j == s.length())
        ans += 2 * (s.length() - i) - 1;
      else if (j == 1) {
        ans += s.length() - i;
        f = 1;
      } else {
        f = 1;
        ans += s.length() - i + j;
      }
    } else {
      int x = 1;
      for (j = 1; j < qq; j++) {
        if (s[i + j] == '1')
          x = 2 * x + 1;
        else
          x = 2 * x;
      }
      if (x <= i + qq) ans++;
      for (j = 1; j < qq; j++) {
        if (s[i + j] == '0') break;
      }
      if (j == qq) {
        if (i + qq != s.length()) {
          ans += 2 * (qq - 1);
          if (s[i + j] == '0') ans++;
          f = 1;
        } else
          ans += 2 * (qq - 1);
      } else if (j == 1) {
        ans += qq - 1;
        f = 1;
      } else {
        ans += qq - 1 + j;
        f = 1;
      }
    }
    if (f == 0) break;
    s = s.substr(i + j, s.length() - i - j);
  }
  return ans;
}
int main() {
  int val = 1;
  vector<int> umap;
  for (int i = 2; i < 19; i++) {
    umap.push_back(val);
    val = 2 * val + i;
  }
  int q;
  cin >> q;
  while (q-- > 0) {
    string s;
    cin >> s;
    cout << func(s, umap) << endl;
  }
}
