#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int i, j, k;
  int len1 = s.length();
  pair<int, int> p[len1];
  for (i = 0; i < len1; i++) {
    p[i].first = s[i] - '0';
    p[i].second = i;
  }
  sort(p, p + len1);
  int sum = 0;
  for (i = 0; i < len1; i++) {
    if (p[i].first == 1 && p[i - 1].first == 1)
      sum += (p[i].second - p[i - 1].second - 1);
  }
  cout << sum << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
