#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string str;
    int sum = 0, ct = 0;
    bool test = true;
    cin >> str;
    int n = str.length();
    for (int i = 0; i < n; i++) {
      if (str[i] == '1') {
        i++;
        for (int j = i; j < n; j++, i++)
          if (str[j] == '0')
            ct++;
          else
            break;
        if (ct != 0 && str[i] == '1') {
          sum += ct;
          ct = 0;
        }
        i--;
      }
    }
    cout << sum << endl;
  }
}
