#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int j = 0; j < t; j++) {
    string str;
    cin >> str;
    int first = 0, last = 0, cnt = 0;
    for (int i = 0; i < str.size(); i++) {
      if (str[i] == '1') {
        first = i;
        break;
      }
    }
    for (int i = str.size() - 1; i >= 0; i--) {
      if (str[i] == '1') {
        last = i;
        break;
      }
    }
    for (int i = first; i < last; i++) {
      if (str[i] == '0') cnt++;
    }
    cout << cnt << endl;
  }
}
