#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
void tmain() {
  string s;
  cin >> s;
  int ones = 0;
  int zeroes = 0;
  int ans = 0;
  for (char c : s) {
    if (c == '0') {
      if (ones) ++zeroes;
    }
    if (c == '1') {
      if (zeroes) {
        if (ones) ones = 0;
        ans += zeroes;
        zeroes = 0;
        ones++;
      } else {
        ones++;
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) tmain();
}
