#include <bits/stdc++.h>
using namespace std;
const long double PI = atan(1.0) * 4;
const int64_t INF = 3e18;
const int32_t LOG = 21;
const long long int MOD = 998244353;
long long int pref[1005];
long long int suf[1005];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int tests = 1;
  cin >> tests;
  for (long long int ii = 0; ii < tests; ii++) {
    string second;
    cin >> second;
    long long int n = second.length();
    fill(suf, suf + n + 3, 0);
    fill(pref, pref + n + 3, 0);
    for (long long int i = 1; i < n + 1; i++) {
      pref[i] = (second[i - 1] - '0') + pref[i - 1];
    }
    for (long long int i = n; i >= 1; i--) {
      suf[i] = (second[i - 1] - '0') + suf[i + 1];
    }
    long long int ans = pref[n];
    ans = min(ans, n - pref[n]);
    for (long long int i = 1; i < n; i++) {
      ans = min(ans, pref[i] + (n - i - suf[i + 1]));
      ans = min(ans, i - pref[i] + suf[i + 1]);
    }
    cout << ans << '\n';
  }
  return 0;
}
