#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    long long suf0 = 0, suf1 = 0;
    for (auto &it : s) {
      suf0 += (it == '0');
      suf1 += (it == '1');
    }
    long long ans = min(suf0, suf1);
    long long pref0 = 0, pref1 = 0;
    for (auto &it : s) {
      pref0 += (it == '0'), suf0 -= (it == '0');
      pref1 += (it == '1'), suf1 -= (it == '1');
      ans = min(ans, pref1 + suf0);
      ans = min(ans, pref0 + suf1);
    }
    cout << ans << "\n";
  }
  return 0;
}
