#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, m, c, x, y, h;
  cin >> t;
  string s;
  for (int j = 0; j < t; j++) {
    c = 0;
    x = -1;
    h = 0;
    y = -1;
    cin >> s;
    m = s.length();
    for (int i = 0; i < m; i++) {
      if (s[i] == '1' && c != 1) {
        c = 1;
        y = i;
      }
      if (c == 1) {
        break;
      }
    }
    c = 0;
    for (int i = m - 1; i >= 0; i--) {
      if (s[i] == '1' && c != 1) {
        c = 1;
        x = i;
      }
      if (c == 1) {
        break;
      }
    }
    if (x != y) {
      for (int i = y + 1; i < x; i++) {
        if (s[i] == '0') {
          h++;
        }
      }
      cout << h << endl;
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}
