#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string str;
  int t, tZero, zero, ans;
  cin >> t;
  for (int i = 0; i < t; i++) {
    tZero = 0;
    zero = 0;
    cin >> str;
    if (str.find('1') == string::npos) {
      cout << "0\n";
      continue;
    }
    for (int i = 0; i < str.length(); i++) {
      if (str[i] == '0')
        zero++;
      else
        break;
    }
    for (int i = str.length() - 1; i >= 0; i--) {
      if (str[i] == '0')
        zero++;
      else
        break;
    }
    for (int i = 0; i < str.length(); i++) {
      if (str[i] == '0') tZero++;
    }
    cout << tZero - zero << endl;
  }
}
