#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    string g;
    cin >> g;
    long long m = 0, n = g.size();
    for (long long k = 0; k < g.size(); k++) {
      if (g[k] == '1') {
        m = max(m, k);
        n = min(n, k);
      }
    }
    if (m == 0 && n == g.size()) {
      cout << '0' << "\n";
    } else {
      long long f = 0;
      for (long long j = n + 1; j < m; j++) {
        if (g[j] == '0') f++;
      }
      cout << f << "\n";
    }
  }
  return 0;
}
