#include <bits/stdc++.h>
using namespace std;
clock_t t1, t2;
double getCurrentTime() {
  t2 = clock();
  return (t2 - t1) / CLOCKS_PER_SEC;
}
int main() {
  t1 = clock();
  int t, len, i, count, sum;
  char ara[102];
  scanf("%d", &t);
  while (t--) {
    cin.ignore(numeric_limits<streamsize>::max(), '\n');
    scanf("%s", ara);
    len = strlen(ara), sum = 0;
    for (i = 1; i < len; i++) {
      while ((ara[i] != '0' || ara[i - 1] != '1') && i < len) i++;
      if (i >= len) break;
      count = 0;
      while (ara[i] != '1' && i < len) {
        i++, count++;
      }
      i == len ? sum += 0 : sum += count;
    }
    printf("%d\n", sum);
  }
}
