#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
using ll = long long;
using pi = pair<int, int>;
char s[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> (s + 1);
    int n = strlen(s + 1);
    for (int i = 1; i <= n; ++i) s[i] = s[i] == '1';
    vector<pi> cz;
    int ans = 0;
    for (int i = 1, tot = 0; i <= n; ++i) {
      if (s[i]) {
        if (tot) cz.emplace_back(make_pair(tot, i));
        tot = 0;
      } else
        ++tot;
      ans += s[i];
      if (i) ans += (s[i - 1] && s[i] == 0);
    }
    for (auto i : cz) {
      for (int j = i.second, k = 0, l = i.first; j <= n; ++j) {
        k *= 2;
        k += s[j];
        ++l;
        if (k > l) break;
        if (k > 2) ++ans;
      }
    }
    cout << ans << endl;
  }
}
