#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    string str;
    cin >> str;
    int len = str.size();
    int z = 0, l = -1, r = -2;
    for (int i = 0; i < len; i++) {
      if (str[i] == '1' && l == -1) l = i;
      if (str[i] == '1') r = i;
    }
    for (int i = l; i <= r; i++)
      if (str[i] == '0') z++;
    cout << z << endl;
    z = 0;
  }
}
