#include <bits/stdc++.h>
using namespace std;
long long tc;
void solve() {
  string s;
  cin >> s;
  int fp = -1, lp = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1' && fp == -1) fp = i;
    if (s[i] == '1') lp = i;
  }
  if (fp == -1)
    cout << "0" << endl;
  else {
    int ans = 0;
    for (int i = fp; i <= lp; i++) {
      if (s[i] == '0') ans++;
    }
    cout << ans << endl;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> tc;
  while (tc--) solve();
  return 0;
}
