#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    string s;
    cin >> s;
    int cnt = 0;
    int idx1 = -1;
    int idx2 = -1;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '1') {
        idx1 = i;
        break;
      }
    }
    for (int i = s.size() - 1; i >= 0; i--) {
      if (s[i] == '1') {
        idx2 = i;
        break;
      }
    }
    int one = 0;
    for (int i = idx1; i <= idx2; i++) {
      if (s[i] == '0') {
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}
