#include <bits/stdc++.h>
using namespace std;
int findlastone(string s) {
  int i, k;
  for (i = s.length() - 1, k = 1; i >= 0; i--, k++) {
    if (s[i] == '1') break;
  }
  return s.length() - k;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int first;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') {
        first = i;
        break;
      }
    }
    int last = findlastone(s);
    int cnt = 0;
    for (int i = first; i <= last; i++) {
      if (s[i] == '0') cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
