#include <bits/stdc++.h>
using namespace std;
long long int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
long long int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long int power(long long int x, 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;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
long long int ncrMod(long long int n, long long int r, long long int p) {
  if (r == 0) return 1;
  long long int fac[n + 1];
  fac[0] = 1;
  for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
void solve() {
  string s;
  cin >> s;
  long long int n = s.size();
  long long int count = 0;
  vector<long long int> oc(n);
  vector<long long int> ec(n);
  if (s[0] == '0') {
    oc[0] = 0;
    ec[0] = 1;
  } else {
    ec[0] = 0;
    oc[0] = 1;
  }
  for (int j = 1; j < n; ++j) {
    if (s[j] == '0') {
      oc[j] = oc[j - 1];
      ec[j] = 1 + ec[j - 1];
    } else {
      ec[j] = ec[j - 1];
      oc[j] = 1 + oc[j - 1];
    }
  }
  long long int ans = 1001;
  for (int j = n - 1; j >= 0; --j) {
    if (s[j] == '1') {
      ++count;
    }
    ans = min(ans, count + ec[j] - 1);
  }
  count = 0;
  for (int j = n - 1; j >= 0; --j) {
    if (s[j] == '0') {
      ++count;
    }
    ans = min(ans, count + oc[j] - 1);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
