#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int sum = 0, flag = 0, prev;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1' && flag == 0) {
        prev = i;
        flag = 1;
      } else if (s[i] == '1' && flag == 1) {
        sum += i - prev - 1;
        prev = i;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
