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