#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 7;
const int base = 131;
const double eps = 0.000001;
char str[200010];
vector<int> v;
vector<int>::iterator it;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    v.clear();
    scanf("%s", str);
    int len = strlen(str);
    for (int i = 0; i < len; i++) {
      if (str[i] == '1') v.push_back(i);
    }
    int ans = 0;
    for (int i = 0; i < len; i++) {
      if (str[i] == '0') {
        it = lower_bound(v.begin(), v.end(), i);
        if (it == v.end())
          continue;
        else {
          int idx = *it;
          int l = idx - i + 1, sum = 0;
          while (idx < len && sum <= l) {
            sum += str[idx] - '0';
            if (sum == l) ans++;
            sum *= 2;
            l++;
            idx++;
          }
        }
      } else {
        ans++;
        if (i < len - 1 && str[i + 1] == '0') ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
