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