#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int TestCase;
  cin >> TestCase;
  string str1;
  for (int i = 1; i <= TestCase; i++) {
    cin >> str1;
    int FirstOne = 0, SecondOne = 0, count = 0;
    for (int j = 0; j < str1.length(); j++) {
      if (str1[j] == '1') {
        FirstOne = j;
      }
    }
    for (int k = str1.length(); k >= 0; k--) {
      if (str1[k] == '1') {
        SecondOne = k;
        count++;
      }
    }
    if (count == 0) {
      cout << 0 << "\n";
    } else {
      cout << FirstOne - SecondOne - count + 1 << "\n";
    }
  }
  return 0;
}
