#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long int t, n;
string second;
int32_t main() {
  ios_base::sync_with_stdio();
  cin.tie();
  cout.tie();
  ;
  cin >> t;
  while (t--) {
    cin >> second;
    n = second.size();
    long long int s1 = -1, s2 = -1;
    for (long long int i = 0; i < n; i++)
      if (second[i] == '1') {
        if (s1 == -1) {
          s1 = i;
        } else
          s2 = i;
      }
    if (s2 == -1) {
      cout << 0 << '\n';
    } else {
      long long int sa = 0;
      for (long long int i = s1; i <= s2; i++) {
        if (second[i] == '0') {
          sa++;
        }
      }
      cout << sa << '\n';
    }
  }
}
