#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  int ipos = -1, fpos = -1;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      ipos = i;
      break;
    }
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') fpos = i;
  }
  int cnt = 0;
  for (int i = ipos; i <= fpos; i++) {
    if (s[i] == '0') cnt++;
  }
  cout << cnt << endl;
  return;
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
