#include <bits/stdc++.h>
char str[1005] = {0};
int prevention_buffer_overflow = 0;
int DP[1005] = {0};
void exec() {
  int result = 1e9;
  scanf("%s", str);
  int n = strlen(str);
  if (n <= 2) {
    printf("0\n");
    return;
  }
  DP[0] = (str[0] == '1');
  for (int i = 1; i < n; i++) DP[i] = DP[i - 1] + (str[i] == '1');
  for (int i = 0; i < n - 1; i++) {
    int _01 = DP[i] + ((n - i - 1) - (DP[n - 1] - DP[i]));
    int _10 = (i + 1 - DP[i]) + (DP[n - 1] - DP[i]);
    if (result > _01) result = _01;
    if (result > _10) result = _10;
  }
  int _00 = 0, _11 = 0;
  for (int i = 0; i < n; i++) _00 += (str[i] == '1');
  _11 = n - _00;
  if (result > _00) result = _00;
  if (result > _11) result = _11;
  printf("%d\n", result);
}
int main() {
  int t = 0;
  scanf("%d", &t);
  while (t--) exec();
}
