#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long int;
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
void solve() {
  string s;
  cin >> s;
  ll st = -1, end = -1;
  for (ll i = 0; i < s.length(); i++) {
    if (s[i] == '1') {
      if (st == -1) {
        st = i;
      }
      end = i;
    }
  }
  ll num = 0;
  for (ll i = st; i <= end; i++) {
    if (s[i] == '0') {
      num++;
    }
  }
  cout << num << "\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  ll t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
