#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int suf0 = 0, suf1 = 0, pref0 = 0, pref1 = 0;
    for (int i = 0; i < s.size(); i++) {
      suf0 += s[i] == '0';
      suf1 += s[i] == '1';
    }
    int ans;
    ans = min(suf0, suf1);
    for (int i = 0; i < s.size(); i++) {
      pref0 += s[i] == '0';
      suf0 -= s[i] == '0';
      pref1 += s[i] == '1';
      suf1 -= s[i] == '1';
      ans = min(ans, pref0 + suf1);
      ans = min(ans, pref1 + suf0);
    }
    cout << ans << endl;
  }
}
