#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    int len = s.length();
    int zero = 0, one = 0;
    for (int i = 0; i < len; i++) {
      if (s[i] == '0')
        zero++;
      else
        one++;
    }
    int ans = min(zero, one);
    int nr1 = 0, nr0 = 0;
    for (int i = 0; i < len; i++) {
      if (s[i] == '0')
        nr0++;
      else
        nr1++;
      ans = min(ans, nr0 + one - nr1);
      ans = min(ans, nr1 + zero - nr0);
    }
    cout << ans << endl;
  }
}
