#include <bits/stdc++.h>
using namespace std;
int t, n, ans, cnt;
char str[110];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf(" %s", str);
    n = strlen(str);
    ans = 0;
    cnt = 0;
    for (int i = 0; i < n; ++i) {
      if (str[i] == '0') {
        if (cnt)
          cnt++;
        else if (i - 1 >= 0 && str[i - 1] == '1')
          cnt = 1;
      } else {
        if (cnt) {
          ans += cnt;
          cnt = 0;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
