#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    int count = 0;
    cin >> s;
    int a = s.find("1");
    int b = s.rfind("1");
    for (int i = a; i <= b; i++) {
      if (s[i] == '0') {
        count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}
