#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long lidx = 0, fidx = 0, ans = 0;
    for (long long i = s.size() - 1; i > 0; i--) {
      if (s[i] == '1') {
        lidx = i;
        break;
      }
    }
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        fidx = i;
        break;
      }
    }
    for (long long i = fidx; i < lidx; i++) {
      if (s[i] == '0') {
        ans++;
      }
    }
    cout << ans << endl;
  }
}
