#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long n = s.size(), count = 0;
    long long i = 0, j = n - 1;
    while (i < n) {
      if (s[i] == '1') break;
      i++;
    }
    while (j >= 0) {
      if (s[j] == '1') break;
      j--;
    }
    while (i <= j) {
      if (s[i] == '0') count++;
      i++;
    }
    cout << count << endl;
  }
  return 0;
}
