#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int k = 0; k < t; k++) {
    string s;
    cin >> s;
    int i = 0;
    while (i < s.length() && s[i] != '1') {
      s[i] = '*';
      i++;
    }
    i = s.length() - 1;
    while (i >= 0 && s[i] != '1') {
      s[i] = '*';
      i--;
    }
    int q = 0;
    for (i = 0; i < s.length(); i++) {
      if (s[i] == '0') q++;
    }
    cout << q << endl;
  }
  getchar();
  getchar();
  return 0;
}
