#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    long long n = str.length();
    long long a = 9e18, b = -1;
    for (long long i = 0; i < n; i++) {
      if (str[i] == '1') {
        a = i + 1;
        break;
      }
    }
    for (long long i = n - 1; i >= 0; i--) {
      if (str[i] == '1') {
        b = i - 1;
        break;
      }
    }
    long long cnt = 0;
    for (long long i = a; i <= b; i++) {
      if (str[i] == '0') cnt++;
    }
    cout << cnt << "\n";
  }
  return 0;
}
