#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1;
  int n, i, cnt, j, a, b, t, len;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> s1;
    cnt = 0;
    len = s1.length();
    for (j = 0; j < len; j++) {
      if (s1[j] == '1') {
        if (cnt == 0) a = j;
        b = j;
        cnt++;
      }
    }
    if (cnt != 0)
      cout << b - a + 1 - cnt << endl;
    else
      cout << 0 << endl;
  }
}
