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