#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  string str;
  for (int o = 0; o < t; o++) {
    cin >> str;
    int n = str.length();
    int pre = 0, suf = 0, total = 0;
    if (str[0] == '1') {
      pre = 0;
    } else {
      pre = 1;
      for (int i = 1; i < n; i++) {
        if (str[i] == '0') {
          pre = pre + 1;
        } else {
          break;
        }
      }
    }
    if (str[n - 1] == '1') {
      suf = 0;
    } else {
      suf = 1;
      for (int j = n - 2; j > 0; j--) {
        if (str[j] == '0') {
          suf = suf + 1;
        } else {
          break;
        }
      }
    }
    for (int k = 0; k < n; k++) {
      if (str[k] == '0') {
        total = total + 1;
      }
    }
    int ans = total - suf - pre;
    if (pre == total) {
      cout << "0" << endl;
    } else {
      cout << ans << endl;
    }
  }
}
