#include <bits/stdc++.h>
using namespace std;
priority_queue<char, vector<char>, greater<char> > pq;
double startTime;
double getCurrentTime() {
  return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
bool isPrime(long long int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int power(long long int x, unsigned long long int y,
                    long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    string s1 = "", s2 = "";
    long long int n = s.size();
    long long int ans = 1e18;
    for (long long int i = 0; i <= n; i++) {
      for (long long int j = 0; j < n; j++) {
        if (j < i)
          s1 += '1';
        else
          s1 += '0';
      }
      for (long long int j = 0; j < n; j++) {
        if (j < (n - i))
          s2 += '0';
        else
          s2 += '1';
      }
      long long int c1 = 0, c2 = 0;
      for (long long int i = 0; i < n; i++) {
        if (s[i] != s1[i]) c1++;
        if (s[i] != s2[i]) c2++;
      }
      ans = min(ans, min(c1, c2));
      s1 = "", s2 = "";
    }
    cout << ans << endl;
  }
  return 0;
}
