#include <bits/stdc++.h>
using namespace std;
int t, ans = 0, tmp = 0;
string s;
bool f = false;
int main() {
  cin >> t;
  getchar();
  while (t > 0) {
    cin >> s;
    int n = s.length();
    for (int i = 0; i < n; i++) {
      if (s[i] == '1') {
        f = true;
        ans += tmp;
        tmp = 0;
      } else {
        if (f == true) {
          tmp++;
        }
      }
    }
    cout << ans << endl;
    t--;
    ans = tmp = 0;
    f = false;
  }
  return 0;
}
