#include <bits/stdc++.h>
using namespace std;
double pi = acos(-1);
long long power(long long a, long long b) {
  long long p_res = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      p_res *= a;
      b--;
    }
    a *= a;
    b /= 2;
  }
  return p_res;
}
long long gcd(long long a, long long b) {
  long long tmp;
  while (b != 0) {
    tmp = a;
    a = b;
    b = tmp % b;
  }
  return a;
}
void solve() {
  string str;
  cin >> str;
  int ans = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '1') {
      int j = i + 1;
      for (; j < str.size(); j++) {
        if (str[j] == '1') {
          ans += j - i - 1;
          break;
        }
      }
    }
  }
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
