#include <bits/stdc++.h>
using namespace std;
int t;
string s;
int l;
int ans;
int main() {
  cin >> t;
  while (t--) {
    cin >> s;
    ans = 0;
    bool ok = false;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '1') {
        if (ok) {
          ans = ans + i - l - 1;
        }
        l = i;
        ok = true;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
