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