#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, x = 0, mi = 0, ma = -1;
  cin >> t;
  string a[t];
  int b[t];
  for (int i = 0; i < t; i++) {
    cin >> a[i];
    for (int j = 0; j < a[i].length(); j++) {
      if (a[i][j] == '1') {
        mi = j;
        break;
      }
    }
    for (int j = a[i].length() - 1; j >= 0; j--) {
      if (a[i][j] == '1') {
        ma = j;
        break;
      }
    }
    for (int j = mi; j <= ma; j++) {
      if (a[i][j] == '0') x++;
    }
    b[i] = x;
    x = 0;
    mi = 0;
    ma = -1;
  }
  for (int i = 0; i < t; i++) {
    cout << b[i] << endl;
  }
  return 0;
}
