#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    que;
stringstream ssin;
const int N = 2e4 + 5, mod = 1e9 + 9, INF = 0x3f3f3f;
int t, n;
char s[N];
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int main() {
  cin >> t;
  while (t--) {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    int Min = INF;
    for (int i = 1; i <= n; ++i) {
      int ans = 0;
      for (int j = 1; j <= i; ++j) {
        if (s[j] != '1') ans++;
      }
      for (int j = i + 1; j <= n; ++j) {
        if (s[j] != '0') ans++;
      }
      Min = min(Min, ans);
    }
    for (int i = 1; i <= n; ++i) {
      int ans = 0;
      for (int j = 1; j <= i; ++j) {
        if (s[j] != '0') ans++;
      }
      for (int j = i + 1; j <= n; ++j) {
        if (s[j] != '1') ans++;
      }
      Min = min(Min, ans);
    }
    cout << Min << endl;
  }
}
