#include <bits/stdc++.h>
using namespace std;
int main() {
  int m;
  cin >> m;
  while (m--) {
    string s;
    cin >> s;
    int f = 0, l = 0;
    bool a = false;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        if (!a) {
          f = i;
          a = true;
        }
        l = i;
      }
    }
    int c = 0;
    for (int i = f; i < l; i++) {
      if (s[i] == '0') c++;
    }
    cout << c << "\n";
  }
  return 0;
}
