#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;
long long int popcount(uint32_t n) {
  n = n - ((n >> 1) & 0x55555555);
  n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
  return ((n + ((n >> 4) & 0xF0F0F0F)) * 0x1010101) >> 24;
}
void Panda() {
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    vector<long long int> ans;
    for (long long int i = -0; i < (long long int)s.size(); i++) {
      if (s[i] == '1') ans.emplace_back(i + 1);
    }
    long long int sum = 0;
    for (long long int i = 1; i < (long long int)ans.size(); i++) {
      sum += ans[i] - ans[i - 1] - 1;
    }
    cout << sum << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Panda();
  return 0;
}
