#include <bits/stdc++.h>
using namespace std;
int fun(vector<char> ans) {
  auto i = ans.begin();
  auto it = ans.end() - 1;
  int count = 0;
  while (*i != '1' && i != ans.end()) {
    i++;
  }
  while (*it != '1' && it != ans.begin() - 1) {
    it--;
  }
  if (i == ans.end() || it == ans.begin() - 1) return count;
  for (; i != it; i++) {
    if (*i == '0') count++;
  }
  return count;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    vector<char> ans;
    ans.clear();
    int i;
    for (i = 0; str[i]; i++) ans.emplace_back(str[i] - '\0');
    if (ans.size() == 1) {
      cout << "0\n";
      continue;
    }
    cout << fun(ans) << "\n";
  }
  return 0;
}
