#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  int c = 0;
  int i = 0;
  while (i < n && s[i] == '0') {
    i++;
  }
  int j = n - 1;
  while (j >= 0 && s[j] == '0') {
    j--;
  }
  if (i >= j) {
    cout << "0\n";
  } else {
    for (; i < j; i++) {
      c += s[i] == '0';
    }
    cout << c << "\n";
  }
}
int main() {
  int q = 1;
  cin >> q;
  while (q--) {
    solve();
  }
}
