#include <bits/stdc++.h>
using namespace std;
int sum[1005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    s = "0" + s;
    sum[0] = 0;
    int n = s.size() - 1, zero = 0, one = 0, i, ans = 0x3f3f3f3f;
    for (i = 1; i <= s.size() - 1; i++) {
      if (s[i] == '0') {
        zero++;
        sum[i] = sum[i - 1] + 1;
      } else {
        one++;
        sum[i] = sum[i - 1];
      }
    }
    ans = min(one, zero);
    for (i = 1; i <= n; i++) {
      ans = min(ans, sum[i] + (n - i - (sum[n] - sum[i])));
    }
    for (i = 1; i <= n; i++) {
      ans = min(ans, i - sum[i] + sum[n] - sum[i]);
    }
    cout << ans << endl;
  }
}
