#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  string s;
  for (int g = 0; g < t; g++) {
    cin >> s;
    int l = s.size();
    int cnt = 0;
    for (int i = 0; i < l; i++) {
      if (s[i] == '1') cnt++;
    }
    int temp = 0, ans = 0;
    for (int i = 0; i < l; i++) {
      if (s[i] == '1') temp = 1;
      if (temp == 1 && cnt > 0) {
        if (s[i] == '0')
          ans++;
        else
          cnt--;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
