#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n, m;
string s;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    int answ = 0;
    int st = -1, en = -1;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == '1') {
        st = j;
        break;
      }
    }
    for (int j = s.size() - 1; j >= 0; j--) {
      if (s[j] == '1') {
        en = j;
        break;
      }
    }
    if (st == -1) {
      cout << 0 << endl;
      continue;
    } else {
      for (int j = st; j <= en; j++) {
        if (s[j] == '0') {
          answ++;
        }
      }
      cout << answ << endl;
    }
  }
  return 0;
}
