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