#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    string s;
    int ones = 0, one = 0, zero = 0;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') ones++;
    }
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1')
        one++;
      else if (one > 0 && one < ones && s[i] == '0')
        zero++;
    }
    cout << zero << endl;
  }
}
