#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int t, ans = 0, cnt = 0;
bool j = 0;
char c[N];
inline int read() {
  int cnt = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (isdigit(c)) {
    cnt = (cnt << 3) + (cnt << 1) + (c ^ 48);
    c = getchar();
  }
  return cnt * f;
}
int main() {
  t = read();
  while (t--) {
    ans = 0;
    cnt = 0;
    j = 0;
    scanf("%s", c + 1);
    int n = strlen(c + 1);
    for (int i = 1; i <= n; i++) {
      if (c[i] == '0' && (j & 1)) {
        cnt++;
      }
      if (c[i] == '1') {
        ans += cnt;
        cnt = 0;
        j = 1;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
