#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int ok = 0;
    int res = 0;
    for (int j = 0; j < s.size() - 1; j++) {
      if (s[j + 1] == '0' && s[j] == '1') {
        while (s[j + 1] != '1' && j < s.size() - 1) {
          ok++;
          j++;
        }
        if (s[j + 1] == '1') {
          res += ok;
          ok = 0;
        }
      }
    }
    cout << res << "\n";
  }
}
