#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int count = 0;
    for (int i = 0; i < s.size(); i++)
      if (s[i] == '0') count++;
    int i = 0, j = 0;
    while (s[i] == '0' && i < s.size()) i++;
    while (s[s.size() - (j + 1)] == '0' && j < s.size()) j++;
    if (j == s.size())
      printf("0\n");
    else
      printf("%d\n", count - (i + j));
  }
}
