#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b, c;
int main() {
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    int g = s.size() - 1, ans = 0, h = 0;
    for (int o = 0; o < s.size(); o++)
      if (s[o] == '1') {
        g = o;
        break;
      }
    for (int o = s.size() - 1; o >= 0; o--)
      if (s[o] == '1') {
        h = o;
        break;
      }
    for (int o = g; o < h; o++)
      if (s[o] == '0') ans++;
    cout << ans << endl;
  }
}
