#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int num_zero = 0, num_one = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '0')
        num_zero++;
      else
        num_one++;
    }
    int ans = min(num_one, num_zero);
    int done_one = 0, done_zero = 0;
    for (int i = 0; i < s.size(); i++) {
      done_zero += (s[i] == '0'), num_zero -= (s[i] == '0');
      done_one += (s[i] == '1'), num_one -= (s[i] == '1');
      ans = min(ans, done_one + num_zero);
      ans = min(ans, done_zero + num_one);
    }
    printf("%d\n", ans);
  }
  return 0;
}
