#include <bits/stdc++.h>
using namespace std;
int query() {
  string s;
  cin >> s;
  int n = s.size();
  int p = -1;
  for (int i = 0; i < n && p == -1; ++i)
    if (s[i] == '1') p = i;
  int q = -1;
  for (int i = n - 1; i >= 0 && q == -1; --i)
    if (s[i] == '1') q = i;
  int cnt = 0;
  for (int i = p; i <= q; ++i) cnt += s[i] == '0';
  cout << cnt << endl;
  return 0;
}
int main() {
  int q;
  cin >> q;
  while (q--) query();
  return 0;
}
