#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i;
  cin >> t;
  for (i = 0; i < t; i++) {
    string s;
    cin >> s;
    int j = 0, k, l = s.length(), sum = 0;
    while (j < l) {
      if (s[j] == '1') {
        k = j;
        j++;
        while (s[j] == '0') j++;
        if (j - k > 1 && s[j] == '1') sum = sum + j - k - 1;
      } else
        j++;
    }
    cout << sum << endl;
  }
  return 0;
}
