#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
void solve() {
  string s;
  cin >> s;
  int l = -1, r = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      l = i;
      break;
    }
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '1') {
      r = i;
      break;
    }
  }
  if (l == -1) {
    cout << "0\n";
    return;
  }
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') ans++;
  }
  ans -= l + s.size() - r - 1;
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  while (n--) solve();
  return 0;
}
