#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string a;
    cin >> a;
    int l = a.find("1"), r = a.rfind("1"), sum = 0, i;
    if (l != -1) {
      for (int i = l; i < r; i++)
        if (a[i] == '0') sum++;
    }
    cout << sum << endl;
  }
}
