#include <bits/stdc++.h>
int main() {
  int a, i, j, mot = 0, baire = 0;
  int sese = 0;
  scanf("%d", &a);
  getchar();
  char b[150];
  while (a--) {
    mot = 0, baire = 0, sese = 0;
    scanf("%s", b);
    int x = strlen(b);
    for (i = 0; i < x; i++) {
      if (b[i] == '0') mot++;
    }
    for (i = 0; i < x; i++) {
      if (b[i] == '0')
        baire++;
      else
        break;
    }
    for (j = x - 1; j >= 0; j--) {
      if (b[j] == '0')
        sese++;
      else
        break;
    }
    if (mot == baire && mot == sese) {
      printf("0\n");
    } else
      printf("%d\n", mot - baire - sese);
  }
  return 0;
}
