#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int t;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    string s;
    cin >> s;
    long long int st = -1;
    for (long long int i = 0; i < s.length(); i++) {
      if (s[i] == '1') {
        st = i;
        break;
      }
    }
    long long int e = -1;
    for (long long int i = s.length() - 1; i >= 0; i--) {
      if (s[i] == '1') {
        e = i;
        break;
      }
    }
    if (st == -1)
      cout << 0 << endl;
    else {
      long long int cnt = 0;
      for (long long int i = st; i <= e; i++) {
        if (s[i] == '0') cnt++;
      }
      cout << cnt << endl;
    }
  }
}
