#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
inline long long add(long long a, long long b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
inline long long sub(long long a, long long b) {
  a -= b;
  if (a < 0) a += 1000000007;
  return a;
}
inline long long mul(long long a, long long b) {
  return (long long)((long long)a * b % 1000000007);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    long long tans = 0;
    bool f1 = 0;
    long long l1 = 0;
    for (long long i = 0; i < s.size(); i += 1)
      if (s[i] == '1') l1 = i;
    for (long long i = 0; i < l1; i += 1) {
      if (s[i] == '0' && !f1)
        continue;
      else if (s[i] == '0' && i < l1)
        tans++;
      else
        f1 = true;
    }
    cout << tans << "\n";
  }
}
