#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e6 + 5;
const int Mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double esp = 1e-6;
char s[MaxN];
int T;
int main() {
  cin >> T;
  while (T--) {
    bool flag = 1;
    int cnt = 0, cnt2 = 0;
    scanf(" %s", &s);
    int len = strlen(s);
    for (int i = 0; i < len; i++) {
      if (s[i] == '1') flag = 0;
      if (flag) continue;
      if (s[i] == '0') cnt++;
    }
    flag = 1;
    for (int i = len - 1; i >= 0; i--) {
      if (s[i] == '1')
        break;
      else
        cnt2++;
    }
    int ans = cnt - cnt2;
    if (ans < 0) ans = 0;
    printf("%d\n", ans);
  }
  return 0;
}
