#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
long long ar[10000010];
long long arr[10000010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t, i, j;
  string s;
  cin >> t;
  while (t--) {
    cin >> s;
    long long b = -1, e = -1, cnt = 0;
    for (i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        b = i;
        break;
      }
    }
    for (j = s.size(); j >= 0; --j) {
      if (s[j] == '1') {
        e = j;
        break;
      }
    }
    if (b == -1 || e == -1) {
      cout << 0 << endl;
    } else {
      for (i = b; i <= e; i++) {
        if (s[i] == '0') {
          cnt++;
        }
      }
      cout << cnt << endl;
    }
  }
}
