#include <bits/stdc++.h>
long long mod = 1000000007;
void normalize(long long &a) { a = (a + mod) % mod; }
long long modmul(long long a, long long b) {
  a = a % mod;
  b = b % mod;
  normalize(a);
  normalize(b);
  return (a * b) % mod;
}
long long modadd(long long a, long long b) {
  a = a % mod;
  b = b % mod;
  normalize(a);
  normalize(b);
  return (a + b) % mod;
}
long long modsub(long long a, long long b) {
  a = a % mod;
  b = b % mod;
  normalize(a);
  normalize(b);
  return (a - b + mod) % mod;
}
long long me(long long x, long long n) {
  x %= mod;
  if (n == 0) return 1;
  long long u = me(x, n / 2) % mod;
  u = (u * u) % mod;
  if (n % 2) u = (u * x) % mod;
  return u;
}
long long ipow(long long a, long long b) {
  long long c = 1;
  while (b--) c *= a;
  return c;
}
long long logb(long long a, long long b) {
  long long ans = 0;
  while (a >= b) {
    a /= b;
    ans++;
  }
  return ans;
}
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void solve() {
  string s;
  long long c = 0, f = -1, l = -1;
  cin >> s;
  for (long long i = 0; i < s.size(); i++) {
    if (f == -1 && s[i] == '1') f = i;
    if (s[i] == '1') l = i;
  }
  for (long long i = f; i <= l; i++) {
    if (s[i] == '0') c++;
    ;
  }
  cout << c << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
