#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long low = s.length(), high = 0, count = 0;
    for (long long i = 0; i < s.length(); i++) {
      if (s[i] == '1') {
        count++;
        low = min(low, i);
        high = max(high, i);
      }
    }
    if (count == 0)
      cout << "0"
           << "\n";
    else
      cout << high - low - count + 1 << "\n";
  }
}
