#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
  cin >> t;
  while (t--) {
    string str;
    cin >> str;
    int x, ans = 0, p = 0;
    int flag = 2;
    for (int i = 0; i < str.length(); i++) {
      x = str[i] - '0';
      if (x == 1 && flag == 0) {
        ans += i - p - 1;
        flag = 1;
        p = i;
      } else if (flag == 2 && x == 1) {
        flag = 1;
        p = i;
      } else if (flag == 1 && x == 0)
        flag = 0;
      else if (flag == 1 && x == 1)
        p = i;
    }
    cout << ans << endl;
  }
  return 0;
}
