#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const long long N = 1e3 + 5;
char s[N];
int suf[N], pre[N];
void solve() {
  cin >> s + 1;
  int n = strlen(s + 1);
  suf[n + 1] = 0;
  for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + (s[i] == '1');
  for (int i = n; i >= 1; i--) suf[i] = suf[i + 1] + (s[i] == '1');
  int ans = INF;
  for (int i = 1; i <= n; i++) {
    int L = min(pre[i], i - pre[i]);
    int R = min(suf[i + 1], (n - i) - suf[i + 1]);
    ans = min(ans, L + R);
  }
  cout << max(ans, 0) << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
