#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;
    int result = 0;
    int count = 0;
    bool check = 0;
    for (int i = 0; i < s.size() - 1; i++) {
      if (s[i] == '1') {
        check = 1;
      }
      if (check > 0 && s[i + 1] == '0') {
        count++;
      }
      if (check > 0 && s[i + 1] == '1') {
        result += count;
        check = 0;
        count = 0;
      }
    }
    cout << result << "\n";
  }
  return 0;
}
