#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const int N = 1000010;
const int maxn = 1e9;
using namespace std;
int t;
int main() {
  cin >> t;
  while (t--) {
    string s;
    bool flag = false;
    int f = 0, e = 0;
    int cnt = 0;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') {
        cnt++;
      }
      if (s[i] == '1' && !flag) {
        f = i;
        e = i;
        flag = true;
      }
      if (s[i] == '1' && flag) {
        e = i;
      }
    }
    if (flag)
      cout << e - f + 1 - cnt << endl;
    else
      cout << 0 << endl;
  }
}
