#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long s = 0, w = 1;
  register char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * w;
}
void print(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
char s[1100];
signed main() {
  for (register long long T = read(); T; T--) {
    long long u, v;
    u = v = 0;
    scanf("%s", s);
    long long n = strlen(s);
    for (register long long i = 0; i < n; i++)
      if (s[i] == '0')
        u++;
      else
        v++;
    long long ans = 1e9;
    for (register long long i = 0; i < n; i++) {
      ans = min(ans, min(u, v));
      if (s[i] == '0')
        u--, v++;
      else
        u++, v--;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
