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