#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long x = 0, p = -2, q = -2, r, ans = 0;
    r = s.length();
    for (long long i = 0; i < r; i++) {
      if (s[i] == '1') {
        p = i;
        break;
      }
    }
    if (p == -2)
      cout << 0;
    else {
      for (long long i = p + 1; i < r; i++) {
        if (s[i] == '0')
          x++;
        else {
          ans += (i - p - 1);
          p = i;
          x = 0;
        }
      }
      cout << ans;
    }
    cout << endl;
  }
  return 0;
}
