#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  cin >> test;
  while (test--) {
    string s1;
    cin >> s1;
    int ans = 0;
    int p = -1, q = -1;
    for (int i = 0; i < s1.size(); i++) {
      if (s1[i] == '1') {
        p = i;
        break;
      }
    }
    for (int i = 0; i < s1.size(); i++) {
      if (s1[i] == '1') {
        q = i;
      }
    }
    for (int i = p; i <= q; i++) {
      if (s1[i] == '0') ans++;
    }
    cout << ans << "\n";
  }
  return 0;
}
