#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, m, q;
int da[maxn];
inline int read() {
  int X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
  return w ? -X : X;
}
int d[1003], c[1003];
int main() {
  int t = read();
  while (t--) {
    string a;
    cin >> a;
    int n = a.size();
    d[0] = 0;
    c[0] = 0;
    int aa = 0, bb = 0;
    for (int i = 0; i < n; i++) {
      if (i) d[i] = d[i - 1], c[i] = c[i - 1];
      if (a[i] == '0')
        aa++, d[i]++;
      else
        bb++, c[i]++;
    }
    int res = 1e8 + 10;
    for (int i = 0; i < n; i++) {
      res = min(res, d[i] + bb - c[i]);
      res = min(res, c[i] + aa - d[i]);
    }
    cout << res << endl;
  }
  return 0;
}
