#include <bits/stdc++.h>
using namespace std;
long long x[100009];
bool a[100009];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int l = 0; l < n; l++) {
    string s;
    int b = 0, e = 0, c = 0;
    cin >> s;
    int sizei = s.size();
    for (int i = 0; i < sizei; i++)
      if (s[i] == '1') {
        b = i + 1;
        break;
      }
    for (int i = (sizei - 1); i >= 0; i--)
      if (s[i] == '1') {
        e = i;
        break;
      }
    for (int i = b; i < e; i++)
      if (s[i] == '0') c++;
    cout << c << "\n";
  }
  return 0;
}
