#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, s, c, i, j;
    string a;
    c = 0;
    cin >> a;
    for (i = 0; a[i] != '\0'; i++) {
      if (a[i] == '1') {
        s = 0;
        for (j = i + 1; a[j] != '\0'; j++) {
          if (a[j] == '0')
            s++;
          else {
            c += s;
            break;
          }
        }
      }
    }
    cout << c << endl;
  }
  return 0;
}
