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