#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    int i = 0, j = str.size() - 1;
    while (str[i] == '0') i++;
    while (str[j] == '0') j--;
    int ans = 0;
    while (i <= j) {
      if (str[i] == '0') ans++;
      i++;
    }
    cout << ans << endl;
  }
  return 0;
}
