#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    if (s.length() == 1) {
      cout << 0 << "\n";
      continue;
    }
    vector<int> v;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') {
        v.push_back(i);
      }
    }
    int c = 0;
    for (int i = 1; i < v.size(); i++) {
      c += v[i] - v[i - 1] - 1;
    }
    cout << c << "\n";
  }
  return 0;
}
