#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    string s;
    cin >> s;
    int cost = 0;
    int mainCost = 0;
    int flag = 0;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == '0') {
        if (flag == 1) {
          cost++;
        }
      } else {
        flag = 1;
        mainCost += cost;
        cost = 0;
      }
    }
    cout << mainCost << "\n";
  }
}
