#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int MAXN = 1005;
int pre[MAXN];
int main(int argc, char const *argv[]) {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int n = s.length();
    for (int i = 1; i <= n; ++i) {
      pre[i] = pre[i - 1] + (s[i - 1] - '0');
    }
    int ans = INF;
    for (int i = 0; i <= n; ++i) {
      int zero_prev = i - pre[i];
      int zero_after = (n - pre[n]) - zero_prev;
      int one_prev = i - zero_prev;
      int one_after = (n - i) - zero_after;
      ans = min(ans, zero_prev + one_after);
      ans = min(ans, one_prev + zero_after);
    }
    cout << ans << "\n";
  }
  return 0;
}
