#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(T &x) {
  for (auto &it : x) {
    cout << it << " ";
  }
  cout << "\n";
};
void solve();
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
void solve() {
  string s;
  cin >> s;
  int suf0, suf1;
  suf0 = count(s.begin(), s.end(), '0');
  suf1 = count(s.begin(), s.end(), '1');
  int ans = min(suf0, suf1);
  int pref0, pref1;
  pref0 = pref1 = 0;
  for (auto &it : s) {
    pref0 += (it == '0'), suf0 -= (it == '0');
    pref1 += (it == '1'), suf1 -= (it == '1');
    ans = min(ans, min(pref0 + suf1, pref1 + suf0));
  }
  cout << ans << '\n';
}
