#include <bits/stdc++.h>
using namespace std;
long long bin_exp(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * a;
    a = a * a;
    n = n >> 1;
  }
  return res;
}
long long bin_exp_modulo(long long a, long long n, long long m) {
  if (a == 0) return 0;
  long long res = 1;
  a = a % m;
  while (n) {
    if (n & 1) res = ((res % m) * (a % m)) % m;
    a = ((a % m) * (a % m)) % m;
    n = n >> 1;
  }
  return res % m;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
void work() {
  string str;
  cin >> str;
  int n = str.length();
  string zero = "", one = "";
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    zero = "";
    one = "";
    for (int j = 0; j < n; ++j) {
      if (j <= i) {
        zero += "0";
        one += "1";
      } else {
        zero += "1";
        one += "0";
      }
    }
    int zz = 0, oo = 0;
    for (int j = 0; j < n; ++j) {
      if (str[j] != zero[j]) ++zz;
      if (str[j] != one[j]) ++oo;
    }
    if (i == 0)
      ans = min(zz, oo);
    else
      ans = min({ans, zz, oo});
  }
  cout << ans;
}
int main() {
  int test;
  cin >> test;
  for (int i = 0; i < test; ++i) {
    work();
    cout << "\n";
  }
  return 0;
}
