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