#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    int n = s.size();
    int p[n];
    for (int i = 0; i < n; i++) p[i] = 0;
    p[0] = (s[0] == '0');
    for (int i = 1; i < n; i++) {
      if (s[i] == '0') {
        p[i] = p[i - 1] + 1;
      } else
        p[i] = 0;
    }
    for (int i = n - 1; i > 0; i--) {
      if (s[i] == '1') p[i] = p[i - 1];
    }
    p[0] = 0;
    for (int i = 0; i < n; i++)
      if (s[i] == '0') p[i] = 0;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') {
        long long x = 1;
        ans++;
        for (int j = i + 1; j < n; j++) {
          if (s[j] == '1')
            x = x * 2 + 1;
          else
            x = x * 2;
          int l = j - i + 1;
          if (p[i] >= x - l) {
            ans++;
          } else
            break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
