#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  for (cin >> t; t; --t) {
    string s;
    cin >> s;
    vector<int> v;
    for (int i = 0; i < s.length(); ++i) {
      int count = 0;
      bool yes = 0;
      if (s[i] == '1' && s[i + 1] == '0') {
        for (int j = i + 1; j < s.length(); ++j) {
          count++;
          if (s[j] == '1') {
            yes = 1;
            count -= 1;
            break;
          }
        }
      }
      if (!yes) count = 0;
      v.push_back(count);
    }
    cout << accumulate(v.begin(), v.end(), 0) << endl;
  }
  return 0;
}
