#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int man = 2e5 + 10;
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T exgcd(T a, T b, T &g, T &x, T &y) {
  if (!b) {
    g = a, x = 1, y = 0;
  } else {
    exgcd(b, a % b, g, y, x);
    y -= x * (a / b);
  }
}
const long long mod = 1e9 + 7;
int n, m;
char str[man];
int main() {
  int t;
  cin >> t;
  while (t--) {
    scanf("%s", str + 1);
    int len = strlen(str + 1);
    long long ans = 0;
    int cnt = 0;
    for (int i = 1; i <= len; i++) {
      if ((str[i] - '0') == 0)
        cnt++;
      else {
        int tp = 0;
        for (int j = i; j <= len && tp <= cnt + j - i + 1; j++) {
          tp <<= 1;
          tp |= (str[j] - '0');
          if (tp <= cnt + j - i + 1) ans++;
        }
        cnt = 0;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
