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