#include <bits/stdc++.h>
using namespace std;
bool b;
string s, t, l;
int i, j, n, m, ans, a[101];
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s;
    int mn = INT_MAX, mx = INT_MIN;
    b = 0;
    for (j = 0; j < s.size(); j++) {
      if (s[j] == '1') {
        mn = min(j, mn);
        mx = max(j, mx);
        b = 1;
      } else if (j + 1 == s.size() && b == 0) {
        cout << 0 << '\n';
      }
    }
    int ans = 0;
    if (b == 0) {
      continue;
    }
    for (j = mn; j < mx; j++) {
      if (s[j] == '0') {
        ans++;
      }
    }
    cout << ans << '\n';
  }
}
