#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long INF = 1e18;
const double eps = 1e-10;
int T;
string s;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> T;
  while (T--) {
    cin >> s;
    int p = 0, e = s.size() - 1;
    bool f = true;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        f = false;
        break;
      }
    }
    if (f) {
      cout << "0\n";
      continue;
    }
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        p = i;
        break;
      }
    }
    for (int i = s.size() - 1; i >= 0; i--) {
      if (s[i] == '1') {
        e = i;
        break;
      }
    }
    int res = 0;
    for (int i = p; i <= e; i++) {
      if (s[i] == '0') res++;
    }
    cout << res << '\n';
  }
  return 0;
}
