#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read() {
  register T sum = 0;
  register char cc = getchar();
  int sym = 1;
  while (cc != '-' && (cc > '9' || cc < '0')) cc = getchar();
  if (cc == '-') sym = -1, cc = getchar();
  sum = sum * 10 + cc - '0';
  cc = getchar();
  while (cc >= '0' && cc <= '9') sum = sum * 10 + cc - '0', cc = getchar();
  return sym * sum;
}
template <typename T>
inline T read(T& a) {
  a = read<T>();
  return a;
}
template <typename T, typename... Others>
inline void read(T& a, Others&... b) {
  a = read(a);
  read(b...);
}
int T;
char str[110];
int main() {
  read(T);
  for (int cas = 1; cas <= T; cas++) {
    scanf("%s", str + 1);
    int len = strlen(str + 1);
    int l = len + 1, r = 0;
    for (int i = 1; i <= len; i++) {
      if (str[i] == '1') {
        l = i;
        break;
      }
    }
    for (int i = len; i >= 1; i--) {
      if (str[i] == '1') {
        r = i;
        break;
      }
    }
    if (l > r) {
      puts("0");
    } else {
      int res = 0;
      for (int i = l; i <= r; i++)
        if (str[i] == '0') res += 1;
      printf("%d\n", res);
    }
  }
  return 0;
}
