#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string p;
    cin >> p;
    int i, x, y, k = 0, q = 0;
    for (i = 0; i < p.size(); i++) {
      if (p[i] == '1') q++;
    }
    if (q == 0)
      cout << 0 << endl;
    else {
      for (i = 0; i < p.size(); i++) {
        if (p[i] == '1') {
          x = i;
          break;
        }
      }
      for (i = (p.size()) - 1; i >= 0; i--) {
        if (p[i] == '1') {
          y = i;
          break;
        }
      }
      k = y - x + 1;
      for (i = x; i <= y; i++) {
        if (p[i] == '1') k--;
      }
      cout << k << endl;
    }
  }
  return 0;
}
