#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int r = 0, re = 0;
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') break;
      re++;
    }
    for (int i = n - 1; i > -1; i--) {
      if (s[i] == '1') break;
      re++;
    }
    for (int i = 0; i < n; i++) {
      if (s[i] == '0') r++;
    }
    if (r == n)
      cout << 0 << endl;
    else
      cout << r - re << endl;
  }
}
