#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int l, r;
    int len = s.size();
    bool flag = false;
    for (int i = 0; i < len; i++) {
      if (s[i] == '1') {
        l = i;
        flag = true;
        break;
      }
    }
    for (int i = len - 1; i >= 0; i--) {
      if (s[i] == '1') {
        r = i;
        flag = true;
        break;
      }
    }
    if (!flag) {
      cout << 0 << endl;
      continue;
    }
    int cnt = 0;
    for (int i = l; i <= r; i++) {
      if (s[i] == '0') {
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
