#include <bits/stdc++.h>
using namespace std;
char s[10000];
int main() {
  int i, t, n, a, b, c;
  cin >> t;
  while (t--) {
    scanf("%s", s + 1);
    a = b = c = 0;
    for (i = 1; s[i]; i++) {
      if (s[i] == '1') {
        c++;
        b = i;
        if (a == 0) a = i;
      }
    }
    if (c)
      cout << b - a + 1 - c << endl;
    else
      cout << 0 << endl;
  }
}
