#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;
ll res;
ll a[N];
void solve() {
  string s;
  cin >> s;
  s = '0' + s + '0';
  ll flag = 0;
  ll idx = 0, idxx = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '1') {
      if (!flag) {
        idx = i;
        flag = 1;
        idxx = i;
      } else {
        idxx = i;
      }
      res++;
    }
  }
  cout << idxx - idx + !(idx == 0) - res << "\n";
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  cin >> t;
  while (t--) {
    solve();
    res = 0;
  }
}
