#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
long long int INF = 1000000005;
long long INFF = 1000000000000000005LL;
const long long int mod = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << " ";
  debug_out(T...);
}
void Panda() {
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long int pos = -1, cnt = 0;
    for (long long int i = 0; i < (long long int)s.size(); i++) {
      if (s[i] == '1' and pos != -1 and i - pos > 1)
        debug_out(i, pos), cnt += i - pos - 1, pos = i;
      else if (s[i] == '1')
        pos = i;
    }
    debug_out();
    cout << cnt << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  Panda();
  return 0;
}
