#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  string s;
  cin >> t;
  bool isOne = true;
  int l, m, j, count;
  for (int i = 0; i < t; i++) {
    cin >> s;
    l = 0, m = 0, j = 0, count = 0;
    isOne = true;
    for (char item : s) {
      if (item == '1') {
        if (isOne) {
          l = j;
          isOne = false;
        }
        m = j;
      }
      j++;
    }
    for (j = l + 1; j < m; j++) {
      if (s[j] == '0') count++;
    }
    cout << count << endl;
  }
}
