#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long int n = s.length();
    long long int st = -1, e = 0;
    long long int ans = 0;
    for (long long int(i) = (0); (i) < (n); (i)++) {
      if (s[i] == '1' && st == -1) {
        st = i;
      } else if (s[i] == '1' && st > -1) {
        e = i;
        ans += e - st - 1;
        st = i;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
