#include <bits/stdc++.h>
using namespace std;
int main() {
  int test, i, j;
  cin >> test;
  while (test--) {
    string a;
    cin >> a;
    int len = a.size(), min = -1, max = -1, count = 0;
    for (i = 0; i < len; i++) {
      if (min == -1 && a[i] == '1') min = i;
      if (a[i] == '1') max = i;
    }
    if (min == -1)
      cout << 0 << endl;
    else {
      for (i = min; i < max; i++) {
        if (a[i] == '0') count++;
      }
      cout << count << endl;
    }
  }
}
