#include <bits/stdc++.h>
static long long int INF = 1e9 + 7;
using namespace std;
template <typename T>
bool comp(T a, T b) {
  if (a < b) return true;
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int inx = -1, inx2 = -1;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1' && inx == -1) {
        inx = i;
      }
      if (s[i] == '1') inx2 = i;
    }
    int cnt = 0;
    for (int i = inx; i <= inx2; i++) {
      if (s[i] == '0') cnt++;
    }
    cout << cnt << "\n";
  }
}
