#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, i = 0, g = 0, start = 0, count = 0;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    n = s.length();
    i = 0;
    g = 0;
    start = 0;
    count = 0;
    while (i < n) {
      if (s[i] == '0' && start) g++;
      if (s[i] == '1' && start == 0) start = 1;
      if (s[i] == '1' && start == 1 && g) {
        count = g;
        start = 1;
      }
      i++;
    }
    cout << count << "\n";
  }
}
