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