#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int flag = 0;
    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1' && flag == 0) {
        flag = 1;
      } else if (s[i] == '0' && flag == 1) {
        ans++;
      }
    }
    for (int i = s.length() - 1; i > 0; i--) {
      if (s[i] == '0') {
        ans--;
      } else
        break;
    }
    cout << max(ans, 0) << "\n";
  }
  return 0;
}
