#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
vector<int> cand;
int prob = 0;
int dfs(vector<pair<int, int> > adj[], int v, bool visited[]) {
  visited[v] = true;
  int i;
  bool flag = false;
  for (i = 0; i < adj[v].size(); i++) {
    if (!visited[adj[v][i].first]) {
      int x = dfs(adj, adj[v][i].first, visited);
      if (x == 0 && adj[v][i].second == 2) {
        cand.push_back(adj[v][i].first);
        flag = true;
      }
      if (x == 1) flag = true;
    }
  }
  if (flag == true) return 1;
  return 0;
}
long long calc(long long a, long long b, long long c) {
  long long x = (a - b) * (a - b) + (b - c) * (b - c) + (a - c) * (a - c);
  return x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int i;
    int count = 0;
    int on = 0;
    int in = -1;
    for (i = s.size() - 1; i >= 0; i--) {
      if (s[i] == '1') {
        in = i + 1;
        break;
      }
    }
    for (i = 0; i < s.size(); i++) {
      if (s[i] == '1') on = 1;
      if (i == in) on = 0;
      if (on == 1 && s[i] == '0') count++;
    }
    cout << count << "\n";
  }
  return 0;
}
