#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, k, i;
  cin >> t;
  for (k = 0; k < t; k++) {
    string s;
    long long int ans = 0, n;
    cin >> s;
    n = s.size();
    for (i = 0; i < s.size(); i++) {
      if (s[i] == '0') ans++;
    }
    if (ans == n) {
      cout << '0' << endl;
      continue;
    }
    i = 0;
    while (i < n && s[i] != '1') {
      ans--;
      i++;
    }
    i = n - 1;
    while (i >= 0 && s[i] != '1') {
      ans--;
      i--;
    }
    cout << ans << endl;
  }
  return 0;
}
