#include <bits/stdc++.h>
using namespace std;
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  cin >> T;
  int cases = 0;
  while (T--) {
    cases++;
    string b;
    cin >> b;
    while (b.back() == '0') {
      b.pop_back();
    }
    int n = b.length();
    int c = 0;
    for (int i = 0; i < n; i++) {
      if (b[i] == '1') {
        for (int j = i + 1; j < n; j++) {
          if (b[j] == '0') {
            c++;
          }
        }
        break;
      }
    }
    cout << c;
    cout << endl;
  }
}
