#include <bits/stdc++.h>
using namespace std;
long long next() {
  long long x;
  cin >> x;
  return x;
}
const long long inf = 4e18, mod = 1e9 + 7;
const int intf = 2e9, maxn = 1e5 + 2;
const double PI = 3.141592653589, eps = 1e-9;
void solve() {
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (s[i] == '0');
  }
  for (int i = 0; i < n && s[i] == '0'; i++) ans--;
  for (int i = n - 1; i >= 0 && s[i] == '0'; i--) ans--;
  cout << max(ans, 0) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  int t = next();
  while (t-- > 0) {
    solve();
  }
  return 0;
}
