#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int l = 0, r = 0;
    string s;
    cin >> s;
    long long int n = s.length();
    for (long long int i = 0; i < n; i++) {
      if (s[i] == '1') {
        l = i;
        break;
      }
    }
    for (long long int i = n - 1; i >= l; i--) {
      if (s[i] == '1') {
        r = i;
        break;
      }
    }
    long long int ans = 0;
    for (long long int i = l; i < r + 1; i++) {
      if (s[i] == '0') ans++;
    }
    if (l == r) ans = 0;
    cout << ans;
    cout << endl;
  }
  return 0;
}
