#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, mk = 0, mz = 1000000, mp = 0;
  cin >> a;
  string s;
  while (a > 0) {
    cin >> s;
    for (long long i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        mk = max(mk, i);
        mz = min(mz, i);
      }
    }
    for (long long j = mz; j <= mk; j++)
      if (s[j] == '0') mp++;
    cout << mp << endl;
    mp = 0;
    mk = 0;
    mz = 100000;
    a--;
  }
  return 0;
}
