#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000000 + 7;
const long long int N = 1000000 + 6;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    int l = -1, r = -1, c = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '1' and c == 0) {
        l = i;
        c++;
      } else if (s[i] == '1' and c != 0)
        r = i;
    }
    int ans = 0;
    if (l != -1)
      for (int i = l; i <= r; i++) {
        if (s[i] == '0') ans++;
      }
    cout << ans << '\n';
  }
}
