#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  cin >> test;
  while (test--) {
    string s;
    int zero = 0, one = 0, i, ans, t1 = 0, t0 = 0, zero_s = 0, one_s = 0,
        cnt = 0;
    cin >> s;
    t1 = count(s.begin(), s.end(), '1');
    t0 = count(s.begin(), s.end(), '0');
    ans = min(t1, t0);
    for (i = 0; i < s.size(); i++) {
      zero = count(s.begin(), s.begin() + i, '0');
      one = count(s.begin(), s.begin() + i, '1');
      zero_s = t0 - zero;
      one_s = t1 - one;
      if (zero < one) {
        cnt = zero + one_s;
      } else {
        cnt = one + zero_s;
      }
      ans = min(ans, cnt);
    }
    cout << ans << endl;
  }
}
