#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long int flag = 0, ans = 0;
    for (long long int i = s.find('1'); i < s.find_last_of('1'); i++) {
      if (s[i] == '0') ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
