#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int l = 0, r = 0;
    if (s.size() == 1) {
      cout << 0 << endl;
    } else {
      int cnt = 0;
      for (int i = 0; i < s.size(); i++) {
        if (s[i] == '1') {
          l = i;
          break;
        }
      }
      for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == '1') {
          r = i;
          break;
        }
      }
      if (l == r) {
        cout << 0 << endl;
      } else {
        for (int i = l; i <= r; i++) {
          if (s[i] == '0') {
            cnt++;
          }
        }
        cout << cnt << endl;
      }
    }
  }
}
