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