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