#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, cnt = 0;
    string s;
    cin >> s;
    n = s.length();
    int st = 0, ed = 0;
    for (int i = 0; i < n; i++)
      if (s[i] == '1') {
        st = i;
        break;
      }
    for (int i = n - 1; i >= 0; i--)
      if (s[i] == '1') {
        ed = i;
        break;
      }
    if (st < ed)
      for (int i = st; i <= ed; i++)
        if (s[i] == '0') cnt++;
    cout << cnt << endl;
  }
  return 0;
}
