#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    char s[100];
    cin >> s;
    int len = strlen(s), left = 0, right = len - 1, sum = 0;
    for (int i = 0; i < len; i++) {
      if (s[i] == '1') {
        left = i;
        break;
      }
    }
    for (int j = len - 1; j >= 0; j--) {
      if (s[j] == '1') {
        right = j;
        break;
      }
    }
    for (int k = left; k <= right; k++) {
      if (s[k] == '0') ++sum;
    }
    if (sum == (right - left + 1)) sum = 0;
    cout << sum << "\n";
  }
  return 0;
}
