#include <bits/stdc++.h>
using namespace std;
int q, x, y, ans, cnt;
string s;
int main() {
  cin >> q;
  while (q--) {
    cin >> s;
    x = y = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') x = 1;
      if (cnt > 0 && s[i] == '1') y = 1;
      if (x == 1 && y == 1) {
        ans += cnt;
        cnt = 0;
        y = 0;
      }
      if (x == 1 && s[i] == '0') cnt++;
    }
    cout << ans << endl;
    ans = cnt = 0;
  }
}
