#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    string s;
    cin >> s;
    int f = 0, ans = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') f = 1;
      if (s[i] == '0' && f) ans++;
    }
    int i = s.size() - 1;
    while (s[i] == '0' && i >= 0 && f) ans--, i--;
    cout << ans << "\n";
  }
  return 0;
}
