#include <bits/stdc++.h>
using namespace std;
map<int, int> za;
int cnt;
int ind;
int main() {
  int t;
  cin >> t;
  for (int k = 0; k < t; k++) {
    string s;
    cin >> s;
    int n = s.size();
    if (n == 1 && s[0] == '0') {
      cout << 0 << endl;
    } else {
      for (int i = 0; i < n; i++) {
        if (s[i] == '1') break;
        s[i] = 'a';
      }
      for (int i = n - 1; i >= 0; i--) {
        if (s[i] == '1') break;
        s[i] = 'a';
      }
      int cnt = 0;
      for (int i = 0; i < n; i++) {
        if (s[i] == '0') cnt++;
      }
      cout << cnt << endl;
      ;
    }
  }
  return 0;
}
