#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int len = s.length();
    int last = 1;
    for (int i = len - 1; i >= 0; i--) {
      if (s[i] == '1') {
        break;
      } else
        last++;
    }
    int l = len - last;
    int f = 0;
    for (int i = 0; i < len; i++) {
      if (s[i] == '1') {
        break;
      } else
        f++;
    }
    int ans = 0;
    for (int i = f; i < l; i++)
      if (s[i] == '0') ans++;
    cout << ans << endl;
  }
  return 0;
}
