#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;
  cin >> t;
  while (t--) {
    int n, k = 0, l = 0, count = 0;
    string second;
    cin >> second;
    n = second.size();
    for (ll i = 0; i < n; i++) {
      if (second[i] == '0') {
        second[i] = '$';
      }
      if (second[i] == '1') break;
    }
    for (ll i = n - 1; i >= 0; i--) {
      if (second[i] == '1') break;
      if (second[i] == '0') second[i] = '$';
    }
    for (ll i = 0; i < n; i++) {
      if (second[i] == '0') count++;
    }
    cout << count << "\n";
  }
  return 0;
}
