#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    int l = str.length();
    int cnt = 0, j = 0, i;
    int arr[l];
    for (i = 0; i < l; i++) {
      if (str[i] == '1') {
        arr[j] = i;
        j++;
      }
    }
    int sum = 0;
    for (i = 1; i < j; i++) {
      sum += arr[i] - arr[i - 1] - 1;
    }
    cout << sum << "\n";
  }
}
