#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    int l = 500;
    int r = 500;
    int c = 0, ans = 0;
    for (int j = 0; j < a.size(); j++) {
      if (a[j] == '1') {
        l = j;
        break;
      }
    }
    for (int j = a.size() - 1; j >= 0; j--) {
      if (a[j] == '1') {
        r = j;
        break;
      }
    }
    for (int j = l; j < r; j++) {
      if (a[j] == '0') {
        c++;
        ans = 1;
      }
    }
    ans = 1;
    if (l == 500 || r == 500) {
      cout << "0" << endl;
    } else if (ans == 1) {
      cout << c << endl;
    }
  }
  return 0;
}
