#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int sum = 0;
  long long int t;
  cin >> t;
  while (t--) {
    string a;
    cin >> a;
    int flag = 0, c = 0;
    for (int i = 0; i < a.length(); i++) {
      if (a[i] == '1' && flag == 0) {
        c = 0;
        flag = 1;
      }
      if (a[i] == '0' && flag == 1) c++;
    }
    if (flag == 1)
      for (int i = a.length() - 1; i >= 0; i--) {
        if (a[i] == '0')
          c--;
        else
          break;
      }
    cout << c << endl;
  }
  return 0;
}
