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