#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 322;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string a;
    cin >> a;
    int first = -1, last = -1;
    for (int i = 0; i < a.size(); i++) {
      if (a[i] == '1') {
        first = i;
        break;
      }
    }
    for (int i = a.size() - 1; i >= 0; i--) {
      if (a[i] == '1') {
        last = i;
        break;
      }
    }
    if (first == -1) {
      cout << 0 << endl;
      continue;
    }
    int ans = 0;
    while (first <= last) {
      if (a[first] == '0') ++ans;
      ++first;
    }
    cout << ans << endl;
  }
  return 0;
}
