#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, n, k, i, j;
  string s;
  cin >> t;
  while (t--) {
    cin >> s;
    for (i = 0; i < s.size(); i++)
      if (s[i] == '1') break;
    for (j = s.size() - 1; j >= 0; j--)
      if (s[j] == '1') break;
    k = 0;
    for (; i < j; i++)
      if (s[i] == '0') k++;
    cout << k << "\n";
  }
  return 0;
}
