#include <bits/stdc++.h>
using namespace std;
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 1e9 + 5;
const long long linf = 1e18;
const double PI = acos(-1.0);
void helper() {
  int t, count, ans;
  cin >> t;
  while (t--) {
    ans = 0;
    count = 0;
    string s;
    cin >> s;
    int flag = 0;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '1') {
        flag = flag | 1;
        ans += count;
        count = 0;
      } else if (flag) {
        count++;
      }
    }
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  helper();
  return 0;
}
