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