#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  char s[100];
  scanf("%d", &test);
  for (int j = 0; j < test; j++) {
    scanf("%s", s);
    int count = 0;
    int ok = 0;
    for (int i = 0; *(s + i); i++) {
      if (s[i] == '1') {
        ok = 1;
      }
      if (ok == 1 && s[i] == '0' && strchr(s + i, '1')) {
        count++;
      }
    }
    printf("%d\n", count);
  }
  return 0;
}
