#include <bits/stdc++.h>
using namespace std;
const int N = 500050;
int t;
int dis(string& a, string& b) {
  int n = a.length(), d = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) d++;
  }
  return d;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    if (n < 3) {
      cout << 0 << endl;
      continue;
    }
    int ans = 1005;
    for (int i = 0; i <= n; i++) {
      int d = n - i;
      string a = string(i, '1') + string(d, '0');
      string b = string(d, '0') + string(i, '1');
      int p = dis(a, s), q = dis(b, s);
      ans = min({ans, p, q});
    }
    cout << ans << endl;
  }
  return 0;
}
