#include <bits/stdc++.h>
using namespace std;
char a[1000];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int x, y, check = 0, s = 0;
    scanf("%s", &a);
    for (int i = 0; i < strlen(a); i++) {
      if (a[i] == '1') {
        check = 1;
        break;
      }
    }
    if (check == 0) {
      cout << "0"
           << "\n";
    } else {
      for (int i = 0; i < strlen(a); i++) {
        if (a[i] == '1') {
          x = i;
          break;
        }
      }
      for (int i = strlen(a) - 1; i >= 0; i--) {
        if (a[i] == '1') {
          y = i;
          break;
        }
      }
      for (int i = x; i <= y; i++) {
        if (a[i] == '0') s = s + 1;
      }
      cout << s << "\n";
    }
  }
}
