#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    char a[1001];
    int b[1001] = {};
    int count1 = 0;
    int count0 = 0;
    scanf("%s", &a);
    int n = strlen(a);
    for (int i = 0; i < strlen(a); i++) {
      if (a[i] == '1') count1++;
      if (a[i] == '0') count0++;
    }
    int z = min(count1, count0);
    int c1_0 = 0, c0_1 = 0;
    for (int i = 0; i < strlen(a); i++) {
      if (a[i] == '1') {
        c1_0++;
        count1--;
      } else {
        c0_1++;
        count0--;
      }
      z = min(z, c1_0 + count0);
      z = min(z, c0_1 + count1);
    }
    printf("%d\n", z);
  }
  return 0;
}
