#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    string s;
    int n, s2 = 0, ans = 0, s1 = 0;
    cin >> s;
    n = s.size() - 1;
    for (int i = n; i >= 0; i--)
      if (s[i] == '1') {
        s2 = i;
        break;
      }
    for (int i = 0; i <= n; i++)
      if (s[i] == '1') {
        s1 = i;
        break;
      }
    for (int i = 0; i <= n; i++) {
      if (i > s1 && i < s2 && s[i] == '0') ans++;
    }
    cout << ans << endl;
  }
}
