#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    char str[10010] = {0};
    int a0[10010] = {0};
    int a1[10010] = {0};
    scanf("%s", str + 1);
    int len = strlen(str + 1);
    for (int i = 1; i <= len; i++) {
      if (str[i] == '1') {
        a1[i] = a1[i - 1] + 1;
        a0[i] = a0[i - 1];
      }
      if (str[i] == '0') {
        a0[i] = a0[i - 1] + 1;
        a1[i] = a1[i - 1];
      }
    }
    int totalt = 1e7;
    for (int i = 1; i <= len; i++) {
      int p = a0[len] - a0[i] + a1[i];
      int p1 = a1[len] - a1[i] + a0[i];
      int total = min(p, p1);
      totalt = min(total, totalt);
    }
    printf("%d\n", totalt);
  }
  return 0;
}
