#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  string s;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int cnt0 = 0;
    cin >> s;
    for (int i = s.find('1'); i < s.find_last_of('1'); ++i) {
      if (s[i] == '0') cnt0++;
    }
    printf("%d\n", cnt0);
  }
}
