#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
inline long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long lowbit(long long x) { return (x & -x); }
inline long long kissme(long long x, long long y) {
  long long res = 1;
  if (x == 0) return 1;
  if (x == 1) return y;
  res = kissme(x / 2, y);
  res = res * res % mod;
  if (x % 2 == 1) res = res * y % mod;
  return res;
}
void read(int &x) {
  int f = 1;
  x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  x *= f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
int T, n, x[N];
string s;
void solve() {
  vector<int> v;
  v.clear();
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      v.push_back(i);
    }
  }
  if (v.empty())
    cout << "0\n";
  else
    cout << v[v.size() - 1] - v[0] + 1 - v.size() << endl;
  return;
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> T;
  while (T--) {
    cin >> s;
    solve();
  }
  return 0;
}
