#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, x, y, a, b;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int len = s.length();
    int fo = 0, lo = 0;
    for (int i = 0; i < len; i++) {
      if (s[i] == '1') {
        fo = i;
        break;
      }
    }
    for (int i = len - 1; i >= 0; i--) {
      if (s[i] == '1') {
        lo = i;
        break;
      }
    }
    if (fo < lo) {
      vector<char> vec;
      for (int i = fo; i <= lo; i++) {
        vec.push_back(s[i]);
      }
      int cnt = count(vec.begin(), vec.end(), '0');
      cout << cnt << "\n";
    } else
      cout << 0 << "\n";
  }
}
