#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, sum = 0;
  string s;
  cin >> t;
  for (int i = 0; i < t; i++) {
    sum = 0;
    cin >> s;
    int left = 0, right = s.size() - 1;
    for (left; left < s.size() - 1; left++) {
      if (s[left] == '1') break;
    }
    for (right; right > 0; right--) {
      if (s[right] == '1') break;
    }
    for (left; left < right; left++) {
      if (s[left] == '0') sum++;
    }
    cout << sum << endl;
  }
  return 0;
}
