#include <bits/stdc++.h>
using namespace std;
long long int large = 1e9 + 7;
int main() {
  long long int tc;
  cin >> tc;
  while (tc--) {
    long long int cnt = 0;
    string str;
    cin >> str;
    long long int n = str.size();
    long long int s = 0, e = n - 1;
    while (s < n && str[s] != '1') {
      s++;
    }
    while (e >= 0 && str[e] != '1') {
      e--;
    }
    if (s == e) {
      cout << "0\n";
    } else {
      for (long long int i = s; i <= e; i++) {
        if (str[i] == '0') cnt++;
      }
      cout << cnt << "\n";
    }
  }
}
