#include <bits/stdc++.h>
using namespace std;
char s[110];
int main() {
  int T;
  cin >> T;
  while (T--) {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    int sum = 0, l, r;
    for (int i = 1; i <= n; i++)
      if (s[i] == '1') sum++;
    for (int i = 1; i <= n; i++)
      if (s[i] == '1') {
        l = i;
        break;
      }
    for (int i = n; i >= 1; i--)
      if (s[i] == '1') {
        r = i;
        break;
      }
    if (sum == 0 || sum == 1)
      printf("0\n");
    else
      printf("%d\n", r - l + 1 - sum);
  }
  return 0;
}
