#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int i, k, cnt = 0;
    for (i = 0; i < s.length(); i++)
      if (s[i] != '0') break;
    k = i;
    for (i; i < s.length(); i++)
      if (s[i] == '0') cnt++;
    for (int j = s.length(); j >= k; j--) {
      if (s[j] == '0')
        cnt--;
      else if (s[j] == '1')
        break;
    }
    cout << cnt << endl;
  }
  return 0;
}
