#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
char s[maxn];
int pre[maxn];
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long ans = 0;
    cin >> s + 1;
    int d = strlen(s + 1);
    for (int i = 1; i <= d; i++) {
      if (s[i] == '1') ans++;
      if (i < d && s[i] == '1' && s[i + 1] == '0') ans++;
      pre[i] = pre[i - 1];
      if (s[i] == '0') pre[i]++;
    }
    for (int i = 1; i < d; i++) {
      if (s[i] == '0' && s[i + 1] == '1') {
        long long temp = 0, l = i, r = i;
        while (1) {
          if (r + 1 <= d) {
            r++;
            temp = temp * 2 + s[r] - '0';
            l = r - temp + 1;
            if (l >= 1 && pre[i] - pre[l - 1] == i - l + 1) {
              if (l <= i) {
                ans++;
              }
            } else
              break;
          } else
            break;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
