#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    int count = 0;
    int si = 0;
    int ei = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') {
        si = i;
        break;
      }
    }
    for (int i = n - 1; i >= 0; i--) {
      if (s[i] == '1') {
        ei = i;
        break;
      }
    }
    for (int i = si; i < ei; i++) {
      if (s[i] == '0') {
        count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}
