#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  int n;
  cin >> n;
  while (n--) {
    string second;
    cin >> second;
    int ans = 0, first = 0;
    int las = 0;
    for (int i = second.length() - 1; i >= 0; i--) {
      if (second[i] == '1') {
        las = i;
        break;
      }
    }
    for (int i = 0; i < second.length(); i++) {
      if (second[i] == '1') {
        if (first == 0) {
          first = 1;
        }
      }
      if (second[i] == '0') {
        if (first == 1 && i <= las) ans++;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
