#include <bits/stdc++.h>
using namespace std;
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
  for (T &i : arr) {
    in >> i;
  }
  return in;
}
template <class T>
ostream &operator<<(ostream &in, vector<T> &arr) {
  for (T &i : arr) {
    in << i << " ";
  }
  return in;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  long long t;
  cin >> t;
  for (long long(i) = 0; (i) < (t); ++(i)) {
    string ss;
    cin >> ss;
    long long k = ss.size();
    long long ch = 0;
    for (int i = 0; i < k; ++i) {
      if (ss[i] == '0') {
        ch += 1;
      }
    }
    long long cu = 0;
    long long ans = 1e9;
    for (int i = 0; i < k; ++i) {
      if (ss[i] == '0') cu += 1;
      long long ca = i + 1 - cu;
      ca += ch - cu;
      ans = min(ans, ca);
      ans = min(ans, k - ca);
    }
    cout << ans << endl;
  }
}
