#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int res[N];
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int o = 0, z = 0;
    for (int i = 0; i < ((int)s.size()); i++) {
      z += s[i] == '0';
      o += s[i] == '1';
    }
    int res = 1000;
    int zz = 0, oo = 0;
    for (int i = 0; i < ((int)s.size()); i++) {
      res = min(res, oo + z);
      res = min(res, zz + o);
      zz += s[i] == '0';
      oo += s[i] == '1';
      z -= s[i] == '0';
      o -= s[i] == '1';
    }
    res = min({res, oo + z, zz + o});
    cout << res << endl;
  }
}
