#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int cnt = 0;
    int ind1 = 0;
    int ind2 = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        ind1 = i;
        break;
      }
    }
    for (int i = s.size() - 1; i >= 0; i--) {
      if (s[i] == '1') {
        ind2 = i;
        break;
      }
    }
    if (ind1 == ind2 && ind2 == 0) {
      cout << 0 << '\n';
      continue;
    }
    for (int i = ind1; i <= ind2; i++) {
      if (s[i] == '0') cnt++;
    }
    cout << cnt << '\n';
  }
  return 0;
}
