#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int ct = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '0') ct++;
    }
    if (ct == s.length()) {
      cout << 0 << "\n";
      continue;
    }
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') break;
      ct--;
    }
    for (int i = s.length() - 1; i >= 0; i--) {
      if (s[i] == '1') break;
      ct--;
    }
    cout << ct << "\n";
  }
}
