#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
const int MAXN = 2e5 + 10;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    int n = s.size();
    int res = n;
    for (int i = 0; i <= n; i++) {
      int op1 = 0;
      int op2 = 0;
      for (int j = 0; j < i; j++) {
        if (s[j] != '0')
          op1++;
        else
          op2++;
      }
      for (int j = i; j < n; j++) {
        if (s[j] != '1')
          op1++;
        else
          op2++;
      }
      res = min(res, min(op1, op2));
    }
    cout << res << endl;
  }
  return 0;
}
