#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
const long long inf = 1e18;
template <typename T>
void read(T &x) {
  x = 0;
  int flag = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
  x = x * flag;
}
template <typename T>
void print(T x) {
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
template <typename T>
T mul(T a, T b) {
  a %= mod;
  b %= mod;
  return a * b % mod;
}
long long qkmod(long long base, long long cnt) {
  long long res = 1;
  base %= mod;
  while (cnt) {
    if (cnt & 1) res = res * base % mod;
    base = base * base % mod;
    cnt >>= 1;
  }
  return res;
}
int main() {
  int T;
  string s;
  cin >> T;
  while (T--) {
    cin >> s;
    int sta = 0, end = s.length() - 1;
    while (sta < s.length() && s[sta] == '0') sta++;
    while (end && s[end] == '0') end--;
    int ans = 0;
    for (int i = sta; i <= end; i++)
      if (s[i] == '0') ans++;
    cout << ans << endl;
  }
}
