#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int f = -1, l = -1;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1' && f == -1) {
        f = i;
        l = i;
        continue;
      }
      if (s[i] == '1' && f != -1) {
        l = i;
        continue;
      }
    }
    int z = 0;
    for (int i = f; i < l; i++) {
      if (s[i] == '0') z++;
    }
    cout << z << endl;
  }
  return 0;
}
