#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    long long ss = s.size();
    long long tmp = -1, jum = 0;
    for (int i = 0; i < ss; i++) {
      if (s[i] == '1') {
        if (tmp != -1) {
          jum += i - tmp - 1;
        }
        tmp = i;
      }
    }
    cout << jum << endl;
  }
}
