#include <bits/stdc++.h>
using namespace std;
bool isZero(int n) { return n == 0; }
void solve() {
  string s;
  cin >> s;
  vector<int> cnt;
  int c = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '0') {
      c++;
    } else {
      cnt.push_back(c);
      c = 0;
    }
  }
  cnt.push_back(c);
  int ans = 0;
  for (int i = 1; i < cnt.size() - 1; ++i) ans += cnt[i];
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
}
