#include <bits/stdc++.h>
using namespace std;
int arr[1001][1001];
int main() {
  std::ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string a;
    cin >> a;
    int cnt = 0;
    int coun = 0;
    bool ok = 1;
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == '0') {
        cnt++;
      } else {
        break;
      }
    }
    for (int i = (a.size() - 1); i >= 0; i--) {
      if (a[i] == '0') {
        cnt++;
      } else {
        break;
      }
    }
    for (int j = 0; j < a.size(); j++) {
      if (a[j] == '0') {
        coun++;
      } else {
        ok = 0;
      }
    }
    if (ok) {
      cout << 0 << endl;
    } else {
      cout << coun - cnt << endl;
    }
  }
  return 0;
}
