#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    string n;
    cin >> n;
    int count = 0;
    while (n[count] == '0') {
      count++;
    }
    int end = n.size() - 1;
    while (n[end] == '0') {
      end--;
    }
    int sum = 0;
    for (int i = count; i <= end; i++) {
      sum += (n[i] == '0');
    }
    cout << sum << endl;
  }
  return 0;
}
