#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    bool f = false;
    int counter = 0;
    int tcount = 0;
    for (int i = 0; i < s.length(); i++) {
      if (!f) {
        if (s[i] == '1') f = true;
      } else {
        if (s[i] == '0') {
          tcount++;
        } else {
          counter += tcount;
          tcount = 0;
        }
      }
    }
    cout << counter << endl;
  }
}
