#include <bits/stdc++.h>
using namespace std;
char str[1010];
int cnt[2][1010];
int main() {
  int t;
  scanf(" %d", &t);
  while (t--) {
    memset(cnt, 0, sizeof cnt);
    scanf(" %s", str + 1);
    int n = strlen(str + 1);
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < 2; j++) cnt[j][i] += cnt[j][i - 1];
      cnt[str[i] - '0'][i]++;
    }
    int ans = 1e9;
    for (int i = 1; i <= n + 1; i++)
      ans = min(
          ans,
          min(i - 1 - cnt[1][i - 1] + n - i + 1 - cnt[0][n] + cnt[0][i - 1],
              i - 1 - cnt[0][i - 1] + n - i + 1 - cnt[1][n] + cnt[1][i - 1]));
    printf("%d\n", ans);
  }
  return 0;
}
