#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  string s;
  cin >> t;
  vector<int> v(t);
  for (int j = 0; j < t; ++j) {
    cin >> s;
    int g = -1, f = 1;
    if (s[s.size() - 1] == 48)
      for (int i = s.size() - 1; f == 1 && i > 0; --i) {
        if (s[i] == 49) f = 0;
        if (s[i] == 48) g = i;
      }
    if (g == -1)
      for (int i = 0; i < s.size() - 1; ++i)
        if (s[i] == 49 && s[i + 1] == 48) {
          s[i + 1] = 49;
          v[j]++;
        }
    if (g != -1)
      for (int i = 0; i < s.size() && i < g - 2; ++i)
        if (s[i] == 49 && s[i + 1] == 48) {
          v[j]++;
          s[i + 1] = 49;
        }
  }
  for (int i = 0; i < t; ++i) cout << v[i] << endl;
  return 0;
}
