#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    while (s.size() && s[0] == '0') {
      s.erase(s.begin());
    }
    while (s.size() && s[(int)s.size() - 1] == '0') {
      s.erase(s.begin() + (int)s.size() - 1);
    }
    int cnt = 0;
    for (auto x : s) cnt += (x == '0');
    cout << cnt << endl;
  }
  return 0;
}
