#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, sum = 0, a = '0';
  cin >> t;
  for (i = 0; i < t; i++) {
    string s;
    int j, l, m;
    cin >> s;
    l = s.find("1");
    m = s.rfind("1");
    for (j = l; j <= m; j++) {
      if (s[j] == '0') {
        sum = sum + 1;
      } else {
      }
    }
    cout << sum << endl;
    sum = 0;
  }
}
