#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  for (int j = 0; j < t; j++) {
    long long int i = 0, count1 = 0, count2 = 0, count = 0;
    string s;
    cin >> s;
    for (i = 0; i < s.size(); i++) {
      if (s[i] == '0') {
        count++;
      }
    }
    for (i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        break;
      }
      count1++;
    }
    for (i = s.size() - 1; i >= 0; i--) {
      if (s[i] == '1') {
        break;
      }
      count2++;
    }
    int ans = count - count1 - count2;
    if (ans <= 0) {
      cout << 0 << "\n";
    } else {
      cout << ans << "\n";
    }
  }
}
